Javascript 获得;InvalidCharacterError:字符串包含无效字符;用于列表框中的选项
我的jsp文件中有以下行:Javascript 获得;InvalidCharacterError:字符串包含无效字符;用于列表框中的选项,javascript,jsp,Javascript,Jsp,我的jsp文件中有以下行: var option = document.createElement('<option value="NO">'); var option=document.createElement(“”); 不知道为什么会出现InvalidCharacterError 有其他选择吗?您可以使用此代码添加到标记中 var myoption = document.createElement("option"); myoption.setAttribute(
var option = document.createElement('<option value="NO">');
var option=document.createElement(“”);
不知道为什么会出现InvalidCharacterError
有其他选择吗?您可以使用此代码添加到标记中
var myoption = document.createElement("option");
myoption.setAttribute("value", "carvalue");
var text = document.createTextNode("maruti");
myoption.appendChild(text);
document.getElementById("mySelect").appendChild(myoption);
DOM实现发生了变化。 之前,您可以创建一个包含代码的新元素,例如: 坏的 var anElement = document.createElement("<A HREF=\"http://stackoverflow.com \">StackOverflow</A>") var anElement = document.createElement("a") anElement.innerHTML = ("<A HREF=\"http://stackoverflow.com \">StackOverflow</A>") var anElement=document.createElement(“”) 现在,此实现返回此“InvalidCharacterError”。 现在必须做的是创建元素并使用innerHTML属性或任何节点的不同特定属性填充它 好 var anElement = document.createElement("<A HREF=\"http://stackoverflow.com \">StackOverflow</A>") var anElement = document.createElement("a") anElement.innerHTML = ("<A HREF=\"http://stackoverflow.com \">StackOverflow</A>") var anElement=document.createElement(“a”)
anElement.innerHTML=(“”)我想您错过了
'
元素。首先创建
,然后添加此'
。完整错误为InvalidCharacterError:未能在“文档”上执行“createElement”:提供的标记名('')不是有效名称。
您需要将其包含在选择
元素中