javascript 使用另一个输入值自动填充输入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28798828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 09:35:24 来源:igfitidea点击:
Autofill input with another input values
提问by Victor Vizcaino
I need to autofill an input field with the values of another input fields. So far I have this:
我需要用另一个输入字段的值自动填充一个输入字段。到目前为止,我有这个:
$("#field1, #field2").keyup(function(){
$("#result").val(this.value);
});
<input type="text" id="field1" name="field1" value="" >
<input type="text" id="field2" name="field2" value="" >
//* to be filled with the values of the inputs above *//
<input type="text" id="result" name="resut" value="">
回答by Telokis
What about
关于什么
$("#field1, #field2").keyup(function(){
update();
});
function update() {
$("#result").val($('#field1').val() + " " + $('#field2').val());
}
$("#field1, #field2").keyup(function(){
update();
});
function update() {
$("#result").val($('#field1').val() + " " + $('#field2').val());
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="field1" name="field1" value="" >
<input type="text" id="field2" name="field2" value="" >
<br>
<input type="text" id="result" name="resut" value="">
回答by JJEMBA KENNETH
$("#field1, #field2").keyup(function(){
update();
});
function update() {
$("#result").val($('#field1').val() + " " + $('#field2').val());
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="field1" name="field1" value="" >
<input type="text" id="field2" name="field2" value="" >
<br>
<input type="text" id="result" name="resut" value="">
$("#field1, #field2").keyup(function(){
update();
});
function update() {
var a = $('#field1').val();
var b = $('#field2').val();
$("#result").val('x');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="field1" name="field1" value="" >
<input type="text" id="field2" name="field2" value="" >
<br>
<input type="text" id="result" name="resut" value="">