Error: SYNTAX_ERR: DOM Exception 12

一个人想着一个人 提交于 2019-12-13 14:21:00

问题


I got the error 'Error: SYNTAX_ERR: DOM Exception 12' with this code:

var html = '<table><tr><td></td><td><input type="text" name="textArea" value="some text" /></td></tr></table>';
$(this.propertyContainer).html(html)

But NOT with this code:

$(this.propertyContainer).html('<table><tr><td></td><td><input type="text" name="textArea" value="some text" /></td></tr></table>')

Here is the html of propertyContainer:

<div xmlns="http://www.w3.org/1999/xhtml" class="property-grid" style="position: absolute; top: 35px; left: 0px;" id="ext-gen126"></div>

Do you have any idea?


回答1:


I found it. I forgot the character '/' at the end of the input tag...

I guess it's because of the 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"
>

Sorry for that...




回答2:


No error here: http://jsfiddle.net/PA4Eg/

Possible mistake is one with the context, I guess (the meaning of this).

The source:

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);
​

In the example bellow my source is the same:

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);
}
​

I use function to set the HTML content of the given div. For this function I use obj as context. It works again. I hope you'll fix your code by comparing it with the one above.



来源:https://stackoverflow.com/questions/13950930/error-syntax-err-dom-exception-12

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!