如何将输入 1 中的值转移到 2 中并添加一些字母?
<script type="text/javascript">
function doit(){
document.getElementById('input2').value=document.getElementById('input1').value;
}
</script>
输入1:2342
输入2:pcid2342d
有人能帮我吗?
如何将输入 1 中的值转移到 2 中并添加一些字母?
<script type="text/javascript">
function doit(){
document.getElementById('input2').value=document.getElementById('input1').value;
}
</script>
输入1:2342
输入2:pcid2342d
有人能帮我吗?
只需使用 + 运算符在输入值之前和之后添加一个字符串。
<script type="text/javascript">
function doit(){
document.getElementById('input2').value="pcid" + document.getElementById('input1').value + "d";
}
</script>
字符串连接:
document.getElementById('input2').value = "stuff" + document.getElementById('input1').value + "other stuff";
在处理数字时,您可以从连接空字符串开始,以避免将数字相加而不是连接到字符串(因为运算符评估顺序):
document.getElementById('input2').value = "" + 1234 + 567 + document.getElementById('input1').value + 89;
好吧,您似乎已经完成了这项工作,您只需要单击即可执行它:
<button onclick="doit()">click me</button>
你为什么不在 jQuery 中尝试一些东西呢?
$("#Anything").click(function() {
$("#Field1").val($("#Field2").val());
});
“点击”只是一个假设=)