我试图创建一个包含撇号/单引号的字符串的TextNode。但它总是失败。这是我的示例代码:
var theText= "John's car";
var str = "var par= document.createElement('p');";
str += "par.style.textAlign='left';";
str += "var fnt= document.createElement('font');";
str += "var txt = document.createTextNode('" + theText + "');";
str += "fnt.appendChild(txt);";
str += "par.appendChild(fnt);";
str += myDiv + ".appendChild(par);";
eval(str);