|
是否兼容FireFox,還沒(méi)來(lái)得及測(cè)試。自己覺(jué)得“另存為”和“復(fù)制”功能也比較多余,這里也省略掉了。如果需要Fix Bug或者技術(shù)支持,歡迎給我留言^_^ 具體代碼如下:
復(fù)制代碼 代碼如下:
function RunCode() {
var ele = document.getElementsByTagName("textarea");
for (var i=0; i<ele.length; i++) {
with (ele[i]) {
if (className != "code") continue;
var o = document.createElement("p");
var a = document.createElement("a");
var em = document.createElement("em");
o.className = "runCode";
a.href = "Javascript:;";
a.innerHTML = "運(yùn)行代碼";
a.onclick = function() {
var win = window.open('', "_blank", '');
win.document.open('text/html', 'replace');
win.document.writeln(this.parentNode.previousSibling.value.replace(//u00a0/gi, " "));
win.document.close();
}
em.innerHTML = "(提示:您可以先修改部分代碼再運(yùn)行)";
o.appendChild(a);
o.appendChild(em);
insertAdjacentElement("afterEnd",o);
}
}
}
目前“運(yùn)行代碼”功能是放在Textarea下方的,如果想放在上方,改動(dòng)以下代碼即可。
insertAdjacentElement("afterEnd",o);
this.parentNode.previousSibling.value
其中的replace(//u00a0/gi, " ")主要是為了將被c_function.ASP文件替換的空格( )和Tab( )還原回來(lái)。使用方面當(dāng)然是在所需頁(yè)面onload進(jìn)來(lái)即可,有多少個(gè)className為code的Textarea,就有多少個(gè)“運(yùn)行代碼”功能,夠簡(jiǎn)單吧?
JavaScript技術(shù):在Z-Blog中運(yùn)行代碼[html][/html](純JS版),轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。