node.setAttribute 导致 INVALID_CHARACTER_ERR
我在函数中有以下代码:
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 */
我也尝试更改宽度和高度的名称,但没有成功! 整个错误信息:
未捕获的错误:INVALID_CHARACTER_ERR:DOM 异常 5
谢谢。
解决方案是使用 setAttributeNode 而不是 setAttribute
I have the following code in a function:
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 */
I have also tried to change the names of Width and Height but no success!
The whole error message:
Uncaught Error: INVALID_CHARACTER_ERR: DOM Exception 5
Thanks.
The Solution is to use setAttributeNode instead of setAttribute
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 setAttributeNode() 而不是 setAttribute()
use setAttributeNode() instead of setAttribute()