我在函数中有以下代码:
this.HtmlRef = document.createElement( "canvas" );
if (!this.HtmlRef)
{
return false;
}
this.HtmlRef.appendChild( document.createTextNode( "Your browser doesn't support dynamic graphic drawings (Canvas)!" ) );
var Width = document.createAttribute( "width" );
var Height = document.createAttribute( "height" );
Width.nodeValue = 0;
Height.nodeValue = 0;
this.HtmlRef.setAttribute(Width); /* error */
this.HtmlRef.setAttribute(Height); /* error */
我也尝试过更改 Width 和 Height 的名称,但没有成功! 整个错误信息:
Uncaught Error: INVALID_CHARACTER_ERR: DOM Exception 5
谢谢。
解决方案是使用 setAttributeNode 而不是 setAttribute
最佳答案
使用 setAttributeNode() 而不是 setAttribute()
关于javascript - node.setAttribute 导致 INVALID_CHARACTER_ERR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5793116/