js把一个文本框里的内容复制到多个文本框里

JavaScript013

js把一个文本框里的内容复制到多个文本框里,第1张

<html>

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />

<title>测试</title>

<script src="js/jquery-1.9.1.js"></script>

<script>

function copyValue(){

var copyValue=document.getElementById("input1").value

var copyInput=document.getElementsByClassName("copy")

var copyNum=copyInput.length

for(var i=0i<copyNumi++){

copyInput[i].value=copyValue

}

}

</script>

</head>

<body>

<div><input id="input1" name="" type="text" value="123456"><input id="button1" name="" type="button" value="复制" onClick="copyValue()"></div>

<div><input name="copy" class="copy" type="text" ></div>

<div><input name="copy" class="copy" type="text" ></div>

<div><input name="copy" class="copy" type="text" ></div>

<div><input name="copy" class="copy" type="text" ></div>

<div><input name="copy" class="copy" type="text" ></div>

<div><input name="copy" class="copy" type="text" ></div>

<div><input name="copy" class="copy" type="text" ></div>

</body>

</html>

document.execCommand这个是浏览器方法,当然,因为这个方法,是只有IE独家提供的。

所谓JS兼容,其中之一就是指这样的地方,在别的浏览器里用不了。如果是FF还好,若是CHROME,想复制也挺费劲。

document.getElementById("文本框ID").value="你要的值";

给你的文本框设个文本框ID,将这个放在js的方法里

function text(){

document.getElementById("文本框ID").value="你要的值";

}

<a href="javascript:" onclick="text()">测试</a>