动态标签插入在 Windows IE 或 Firefox 上不起作用
我使用以下策略动态地将 html 标签插入到文档中。它适用于 Mac Chrome 和 Firefox,但不适用于 Windows IE 或 Windows Firefox。我怀疑这与分配给新创建的 div 标签的innerHTML 属性的字符串中的尖括号有关。有什么想法吗?
function addElement() {
var ni = document.getElementById('stateSet');
var newdiv = document.createElement('div');
var divIdName = 'state'+ stateCount;
stateCount++;
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = '<input id="name" type="text"/> <input id="setting" type="text"/><button type="button" >x</button>'
ni.appendChild(newdiv);
}
I am dynamically inserting html tags into the document using the following strategy. It works on Mac Chrome and Firefox but not on Windows IE or Windows Firefox. I suspect this has something to do with the angle brackets in the string assigned to the innerHTML property of the newly created div tag. Any ideas?
function addElement() {
var ni = document.getElementById('stateSet');
var newdiv = document.createElement('div');
var divIdName = 'state'+ stateCount;
stateCount++;
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = '<input id="name" type="text"/> <input id="setting" type="text"/><button type="button" >x</button>'
ni.appendChild(newdiv);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试声明 statecount
http://jsfiddle.net/TPx3v/
Try declaring statecount
http://jsfiddle.net/TPx3v/