我需要使用其他输入字段的值自动填充输入字段。到目前为止,我有这个:
$("#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="">
答案 0 :(得分:4)
怎么样?
$("#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="">
答案 1 :(得分:0)
$("#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="">