在IE和Firefox下,动态创建元素的方法是由区别的

如下面代码,在IE下可以运行,在Firefox下会报错

 var theform = document.forms[0];
 theform.appendChild(document.createElement("<input type='hidden' name='__EVENTTARGET'>"));

在 Firefox 只支持:document.createElement('input')

如果添加属性和事件的话,需要使用setAttribute方法

 

使用jquery动态创建元素,可以同时支持IE、Firefox

 var theform = document.forms[0];

  $("<input type='hidden' name='__EVENTTARGET'>").appendTo(theform);

相关文章:

  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2022-02-07
  • 2022-03-15
猜你喜欢
  • 2022-12-23
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
相关资源
相似解决方案