node.setAttribute вызывает INVALID_CHARACTER_ERR - PullRequest
1 голос
/ 26 апреля 2011

У меня есть следующий код в функции:

  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 */

Я также пытался изменить имена ширины и высоты, но безуспешно!Полное сообщение об ошибке:

Uncaught Error: INVALID_CHARACTER_ERR: DOM Exception 5

Спасибо.

Решение заключается в использовании setAttributeNode вместо setAttribute

1 Ответ

2 голосов
/ 26 апреля 2011

используйте setAttributeNode () вместо setAttribute ()

...