EMLOG 新窗口运行代码
此篇文章主要介绍怎么为EMLOG 代码 插入运行代码 按钮股 并实现新窗口运行
当然这里的代码只能HTML代码
因为 你写 JSCSS 代码 也需要 用 <script>/ <style> 标签 包裹总归还是 HTML
在这里实现的方法 跟后台 无关只是 前台 JS 实现, 当然 前提 还要有 jQuery(老不死)
具体效果 就是本站前台的 运行代码
再插入代码的时候 用 EMLOG 5.3.1 自带编辑器, 只有代码格式 为 HTML 的时候 才起作用
当然 代码 稍微改下 也适合 其他地方应用 具体的自己折腾吧
<title>JS 新窗口运行</title> <h1>JS 新窗口运行</h2>
var preNum = 0;
$("pre[class*='lang-html']").each(function () {
$th = $(this);
id = "preNum_" + preNum;
$th.after("<a onclick=\"runCode('" + id + "')\">运行代码</a>").attr("id", id);
preNum++
});
function runCode(d) {
var c = window.open("", "_blank", "");
c.document.open("text/html", "replace");
c.opener = null;
c.document.write($("#" + d).html()
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, '"')
.replace(/&/g, "&")
);
c.document.close()
}本文出自简爱博客,转载时请注明出处及相应链接。

可以查询手机归属地