当前位置: 代码迷 >> Web前端 >> IE中form元素中的name与id是雷同的
  详细解决方案

IE中form元素中的name与id是雷同的

热度:96   发布时间:2012-10-27 10:42:26.0
IE中form元素中的name与id是相同的
<script type="text/javascript">

     function testIECase(name){
        alert(document.getElementById(name).value);
    }

</script>
<hr />
在ie中获取第一个匹配txtName的元素,name="txtName"是第一个元素
<button onclick="testIECase('txtName')">test txtName</button>
<hr />
在ie中获取第一个匹配txtPassword的元素,id="txtPassword"是第一个元素

<button onclick="testIECase('txtPassword')">test txtPassword</button>
<hr />
<input name="txtName" value="txtName 1"/>

<input id="txtName"  value="txtName 2"/>

<input id="txtPassword"  value="txtPassword 1"/>

<input name="txtPassword"  value="txtPassword 2"/>


<hr />
<br />
<code>
function testIECase(name){
        alert(document.getElementById(name).value);
    }
</code>

?

  相关解决方案