<!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>同步文本框内容的JS代码</title> </head> <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="http://www." name="addr_more1" url="true" /> </p> <p> <input id="addr_more2" size="35" value="http://www." name="addr_more2" url="true" /> </p> <p> <input id="addr_more3" size="35" value="http://www." name="addr_more3" url="true" /> </p> <p> <input id="addr_more4" size="35" value="http://www." name="addr_more4" url="true" /> </p> <p>查找更多代码,请访问:<a href="http://www.lanrentuku.com" target="_blank">懒人图库</a></p> </body> </html>
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)