<!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>
<input type="text" name="wareIndexId" value="33333"/>
<input type="text" name="clientIndexId" value="222"/>
<input type="text" id="wareIndexId" name="wareIndexId" value="111111"/>
<input type="text" id="clientIndexId" name="clientIndexId" value="444444"/>
<script type="text/javascript">
document.getElementById("wareIndexId").value='sssss'</script>
本来是通过Id来改变对象的值的,结果失效了。他们的name属性的值相同!!!!
</body>
</html>

解决方案 »

  1.   

    在FF下没问题,IE下和LZ一样
    在IE下最好不要用相同name吧
      

  2.   

    试试:document.getElementsByName("wareIndexId")[0].value = 'sssss'
      

  3.   

    没看懂你到底要说明什么
    <!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>
    <input type="text" name="wareIndexId" value="33333"/>
    <input type="text" name="clientIndexId" value="222"/>
    <input type="text" id="wareIndexId" name="wareIndexId2" value="111111"/>
    <input type="text" id="clientIndexId" name="clientIndexId2" value="444444"/>
    <script type="text/javascript">
    document.getElementById("wareIndexId").value='sssss'</script>
    本来是通过Id来改变对象的值的,结果失效了。他们的name属性的值相同!!!!
    </body>
    </html>
      

  4.   

    楼主用的是IE6吧,用FF试试,这应该是浏览器的处理方式不一样造成的
      

  5.   


    LZ是说,有俩name="wareIndexId"的input,其中的一个id="wareIndexId"
    现在要改变这个id="wareIndexId"的input的值,却改了另一个没有id的input……
      

  6.   

    写明所有控件的id,肯定是可以获取到的,除非写错了id
      

  7.   

    getElementById只能按照文档流的顺序,获取第一个id值为wareIndexId的元素
    注:IE浏览器可能会识别name属性哦~
      

  8.   

    本身用相同的name就不符合规范
      

  9.   

    ie6的bughttp://blog.csdn.net/cheng5128/archive/2009/11/25/4874718.aspx
      

  10.   


    alert("aaaaaaaa")
    document.getElementById("wareIndexId").value='sssss';//ie6 可以
    alert("as")
    document.getElementsByName("clientIndexId").value = "aaaaaaaaaaaaa";//ie6和ff都不正常
      

  11.   

    html中允许用相同的name吧,这样获取同一名称的控件方便
      

  12.   


    可以name相同,但不要name和id相同
      

  13.   

    jsg2004jack
    说的对,我是用IE7调试的,所以出现了这个问题。用FF和chrome都能正常识别id和name.
      

  14.   


    我是用ActionForm获取表单元素的,所以有时可能会用到相同的name