在ie6,ff3,chrome下测试的
ff,chrome正常
ie6下  name属性应该是设置成功了,后面的2个alert却很奇怪
这是为什么了????
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
 <form id="tf">
  <input id="te" type="text" name="ss" value="123" />
 </form>
<script type="text/javascript">
<!--
window.onload=function(){
var te = document.getElementById('te');
var tf = document.getElementById('tf');
te.setAttribute('name', 'key');
alert(te.name)
alert(tf.key)
alert(tf.ss)
}
//-->
</script>
</body>
</html>

解决方案 »

  1.   

    ff3
    key
    [object HTMLInputElement]
    undefinedie8
    key
    [object HTMLInputElement]
    undefined弹出的东西都一样。被你骗了。
      

  2.   

    汗,这个是所有ie的bug,设置name,之后dom中查不到,
      

  3.   


    我的ie8第二个undefined
    第三个[object]
      

  4.   

    我用的是ie6..........对了  ie8到底是怎么样了的????????
      

  5.   

    这里有:http://blog.guitarbean.com/2009/07/setting-the-name-attribute-in-internet-explorer.html所以有时指定name时只能document.createElement("<input type='text' name='ss'>");//当然只能在ie下
      

  6.   

    用着还成有兼容IE7的模式。
    IE6的问题比较多些,性能不高。
      

  7.   

    我也是这个,在ie8下确实可以出来,不过这个bug看到过好多次了
    在ie tester v0.4下ie6,7,8都有问题
    之前是在傲游下也有问题
      

  8.   

    Microsoft JScript® allows the name to be changed at run time. This does not cause the name in the programming model to change in the collection of elements, but it does change the name used for submitting elements.The NAME attribute cannot be set at run time on elements dynamically created with the createElement method. To create an element with a name attribute, include the attribute and value when using the createElement method.
      

  9.   

    ie6 下 input等控件的name 不能在后续设置,要么用document.createElement("<input name='xxx'>")来设置MSDN的说明:Microsoft JScript allows the name to be changed at run time. This does not cause the name in the programming model to change in the collection of elements, but it does change the name used for submitting elements.The NAME attribute cannot be set at run time on elements dynamically created with the createElement method. To create an element with a name attribute, include the attribute and value when using the createElement method.In Microsoft Internet Explorer 6, This property now applies to the attribute object. 
      

  10.   

    在IE6和IE7中,
    name 是只读属性,因此更改是不起作用的。