日期:2014-05-16  浏览次数:20267 次

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>