document.createElement 参数不可以是变量?
MOOD 2015-06-09 08:54:40 <div>浏览器识别:<span id="info">...</span></div>
<div id="a">loreamloreamloreamloreamloreamloream,loreamloreamloream,loreamloreamloream,loreamloreamloreamloream</div>
<script>
function replaceToH(hh) {
if (document.selection) {//IE
document.getElementById("info").innerHTML="IE";
var z = document.selection.createRange();
var t = z.text;
var v = z.htmlText;
z.select();
z.pasteHTML("<h1>"+v+"</h1>");
} else {//FF
var h="h3";//无论用函数参数,还是在这加个变量作测试
document.getElementById("info").innerHTML="FF";
var z = window.getSelection().getRangeAt(0);
var t = z.toString();
var temp = document.createElement(h);//结果没效果,非得在这直接写上标签名才行,三大浏览器都测试过
//temp.href="#";
temp.innerHTML = t;
z.deleteContents();
z.insertNode(temp);
}
}
document.onmouseup = replaceToH("h1");
</script>
在网上找的代码,改成用变量,结果没效果