当前位置: 代码迷 >> JavaScript >> js中取控件的值解决方法
  详细解决方案

js中取控件的值解决方法

热度:27   发布时间:2012-03-08 13:30:13.0
js中取控件的值
做一个链接触发js函数
函数的主要功能是使用cloneNode复制一个标签(如input   id= 'username '   type= 'text '),再使用appendchild添加
问题是原来被复制的标签的id是username,复制后的标签的id是什么
换句话说,我如何取得复制的标签的id

------解决方案--------------------
<html>
<body>

<input type= "text " id= "txt1 " />

<script>
var txt1=document.getElementById( "txt1 ");
var txt2=txt1.cloneNode(true);

//document.body.appendChild(txt2);

alert(txt2.id)//输出txt1

txt2.id= "txt2 ";

alert(txt2.id);//输出txt2
</script>
</body>
</html>
  相关解决方案