问题
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