同步文本框内容JS代码实现
本文实例为大家分享了同步文本框内容JS代码,供大家参考,具体内容如下
图例1
<html> <body> <script language="JavaScript" type="text/javascript"> function addEvent(eventHandler) { var tags = document.getElementsByTagName('input'); for(var i=0;i<tags.length;i++) { if(tags[i].getAttribute('url') == 'true') { if(tags[i].addEventListener) { tags[i].addEventListener('keyup',eventHandler,true); } else { tags[i].attachEvent('onkeyup',eventHandler); } } } } function addInput(e) { var obj = e.target ? e.target : e.srcElement; var tags = document.getElementsByTagName('input'); for(var i=0;i<tags.length;i++) { if(tags[i].getAttribute('url') == 'true'&&tags[i]!=obj) { tags[i].value = obj.value; } } } window.onload = function() { addEvent(addInput); } </script> <p> <input id="addr_more1" size="35" value="" name="addr_more1" url="true" /> </p> <p> <input id="addr_more2" size="35" value="" name="addr_more2" url="true" /> </p> <p> <input id="addr_more3" size="35" value="" name="addr_more3" url="true" /> </p> <p> <input id="addr_more4" size="35" value="" name="addr_more4" url="true" /> </p> </body> </html>
图例2
<html> <head> <script type="text/javascript" src="jquery-1.4.4.min.js"></script> <script type="text/javascript"> function getNM(id) { var name2 = $("#"+id+"").val(); if (name2 != "") { for(var i=3;i<6;i++) $("#NM"+i+"").val(name2); } } </script> </head> <body> <input type="text" id="NM1" value="" /> <input type="text" id="NM2" value="" /> <input type="text" id="NM3" value="" onkeyup="getNM(this.id)"/> <input type="text" id="NM4" value="" onkeyup="getNM(this.id)"/> <input type="text" id="NM5" value="" onkeyup="getNM(this.id)"/> </body> </html>
需要引用 <script type="text/javascript" src="jquery-1.4.4.min.js"></script>
相关推荐
88274956 2020-11-03
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14
firejq 2020-06-14
firstboy0 2020-06-14
e度空间 2020-06-12
zhongweinan 2020-06-10