我收到错误'错误:SYNTAX_ERR:DOM异常12',代码如下:
var html = '<table><tr><td></td><td><input type="text" name="textArea" value="some text" /></td></tr></table>';
$(this.propertyContainer).html(html)
但不使用此代码:
$(this.propertyContainer).html('<table><tr><td></td><td><input type="text" name="textArea" value="some text" /></td></tr></table>')
这是propertyContainer的html:
<div xmlns="http://www.w3.org/1999/xhtml" class="property-grid" style="position: absolute; top: 35px; left: 0px;" id="ext-gen126"></div>
你有什么想法吗?
答案 0 :(得分:2)
我找到了。我忘记了输入标签末尾的字符'/'...
我想这是因为dtd:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus SVG 1.1//EN"
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"
>
对不起......
答案 1 :(得分:1)
此处没有错误:http://jsfiddle.net/PA4Eg/
可能的错误是上下文,我猜(this
的意思)。
来源:
var obj = {
propertyContainer: document.getElementById('ext-gen126')
},
html = '<table><tr><td></td><td><input type="text" name="textArea" value="some text" /></td></tr></table>';
$(obj.propertyContainer).html(html);
在下面的示例中,我的来源是相同的:
var obj = {
propertyContainer: document.getElementById('ext-gen126')
},
html = '<table><tr><td></td><td><input type="text" name="textArea" value="some text" /></td></tr></table>';
setHtml.call(obj, html);
function setHtml(html) {
$(this.propertyContainer).html(html);
}
我使用函数来设置给定div的HTML内容。对于此函数,我使用obj
作为上下文。它又有效了。我希望你能通过将代码与上面的代码进行比较来修复你的代码。