在FF下发生uncaught exception: String contains an invalid character(NS_ERROR_DOM_INVALID_CHARACTER_ERR)错误的解决办法

来源:互联网 发布:索引超出矩阵维度 编辑:程序博客网 时间:2024/05/29 16:36

 

IE和FF的兼容性确实很让人头疼,

在IE下运行的好好的JS,在FF下发生uncaught exception: String contains an invalid character(NS_ERROR_DOM_INVALID_CHARACTER_ERR)错误,JS部分代码如下:

-------------------------------------------------------------------------------------------------------------

document.$(divId).appendChild(document.createElement('<div id="'+_abc+'" style="position:relative;width:100%;height:100%;overflow:hidden" unselectable="on"></div>'));

-------------------------------------------------------------------------------------------------------------

原因可能是FF不支持动态的设置div的id,所以代码要改成一下的样子:

 

-------------------------------------------------------------------------------------------------------------

 

 var _abc= document.$(divId).appendChild(document.createElement('div'));
  _abc.id = _abc;
  _abc.style.position = 'relative';
  _abc.style.width = '100%';
  _abc.style.height = '100%';
  _abc.style.overflow = 'hidden';
  _abc.unselectable = 'on';

 

-------------------------------------------------------------------------------------------------------------
呵呵,虽然比较麻烦,但是问题解决了