1、点击按钮,一个文本框中的内容粘贴到另一个文本框内。
文本框1: <input type="text" id="txt1" value="Hello World!"><BR><BR>
文本框2: <input type="text" id="txt2"><BR><BR>
<button onclick="document.getElementById('txt2').value=document.getElementById('txt1').value">按钮</button>
2、点击一个文本框,其内容粘贴到另一个文本框内。
方法1:
文本框1:<input type="text" id="txt1" value="Hello World!"onclick="document.getElementById('txt2').value=document.getElementById('txt1').value"><BR><BR>
文本框2: <input type="text" id="txt2">
方法2:
文本框1: <input type="text" id="txx1" value="Hello World!"onclick=Paste()><BR><BR>
文本框2:<input type="text" id="txx2" value="">
<script>
function Paste(){
document.getElementById("txx2").value = document.getElementById("txx1").value;}
</script>
3、点击文本连接,文本粘贴到指定的文本框内。
方法1:
文本框: <input type="text" id="txt"><BR><BR>
<a href="#"onclick="document.getElementById('txt').value='Hello World!'">Hello World!</a>
方法2:
文本框:<form name="form1"><input type="text" id="txt"></form>
<a href="#"onclick="document.form1.txt.value='Hello World!'">Hello World!</a>
查看效果:可用“代码运行框”手动预览效果。
评论