本文介绍了实时复制另一个文本框的值Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得另一个文本框的值并将其实时输入到另一个文本框中。
如何检测TEXT_3是否已更改?如果TEXT_3 VALUE CHANGED,它必须被输入到TEXT_4
为了您的方便,下面是代码和演示:
** HTML **
< label> TEXT 1:< / label>< input type =textid =text_1value =/>
< label> TEXT 2:< / label>< input type =textid =text_2value =/>
< label> TEXT 3:< / label>< input type =textid =text_3value =/>
< label> TEXT 4:< / label>< input type =textid =text_4value =/>
** JAVASCRIPT **
/ *输入TEXT_1和TEXT_2值至TEXT_3 ON TEXT_1 KEYUP * /
$(#text_1)。keyup(function(){$ ($##text_1)。val()++ $(#text_2)。val());
})
/ *在TEXT_1和TEXT_2 KEYUP * /
$(#text_2)上输入TEXT_1和TEXT_2值到TEXT_3。keyup(function(){
$(#text_3) .val($(#text_1)。val()++ $(#text_2)。val());
})
/ *如何操作检测出TEXT_3是否已更改?如果TEXT_3 VALUE CHANGED,它必须被输入到TEXT_4 * /
/ *不工作解决方案* /
$(#text_3)。change(function(){
$(#text_4)。val($(#text_3)。val());
})
DEMO:
感谢您的回应!
解决方案
textbox3.val(),
如下:
$(#text_1)。keyup(function() {
$(#text_3)。val($(#text_1)。val()++ $(#text_2)。val())。change(); $ b $ (b)}
/ *输入TEXT_1和TEXT_2值TEXT_3开启TEXT_1和TEXT_2 KEYUP * /
$(#text_2)。keyup(function(){
$ (#text_3)。val($(#text_1).val()++ $(#text_2).val())。change();
})
I want to get the value of another textbox and input it in realtime into the other textbox.HOW CAN I DETECT IF TEXT_3 WAS CHANGED? IF TEXT_3 VALUE CHANGED, IT MUST BE INPUTTED TO TEXT_4For your convenience, here is the code and the demo:
**HTML**
<label>TEXT 1: </label><input type="text" id="text_1" value=""/>
<label>TEXT 2: </label><input type="text" id="text_2" value=""/>
<label>TEXT 3: </label><input type="text" id="text_3" value=""/>
<label>TEXT 4: </label><input type="text" id="text_4" value=""/>
**JAVASCRIPT**
/* INPUT TEXT_1 AND TEXT_2 VALUE TO TEXT_3 ON TEXT_1 KEYUP*/
$("#text_1").keyup(function() {
$("#text_3").val($("#text_1").val() + " " + $("#text_2").val());
})
/* INPUT TEXT_1 AND TEXT_2 VALUE TO TEXT_3 ON TEXT_1 AND TEXT_2 KEYUP*/
$("#text_2").keyup(function(){
$("#text_3").val($("#text_1").val() + " " + $("#text_2").val());
})
/* HOW CAN I DETECT IF TEXT_3 WAS CHANGED? IF TEXT_3 VALUE CHANGED, IT MUST BE INPUTTED TO TEXT_4*/
/* not working solution */
$("#text_3").change(function(){
$("#text_4").val($("#text_3").val());
})
DEMO: http://jsfiddle.net/8eXRx/7/
Thanks for responses!
解决方案
Add change() after your textbox3.val(),like below:
$("#text_1").keyup(function() {
$("#text_3").val($("#text_1").val() + " " + $("#text_2").val()).change();
})
/* INPUT TEXT_1 AND TEXT_2 VALUE TO TEXT_3 ON TEXT_1 AND TEXT_2 KEYUP*/
$("#text_2").keyup(function(){
$("#text_3").val($("#text_1").val() + " " + $("#text_2").val()).change();
})
这篇关于实时复制另一个文本框的值Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!