如何同步两个文本框表单值? [英] How to synchronize two text box form values?
本文介绍了如何同步两个文本框表单值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我是jQuery的新手.假设我有两个HTML文本框.我如何才能做到:如果我在文本框A中写入,则相同的值将进入文本框B,而如果我在B中写入,则它将写入A,并且与删除文本相同.如何在jQuery中完成?
Hi all i am new to jQuery. Suppose I have two HTML text boxes. How can I make it happen that if I write in text box A then same value goes to textbox B and if I write in B then it goes to A and same as delete the text. How can this be done in jQuery?
推荐答案
这是使用 jQuery 的动态方式:
$(document).ready(function() {
$(".copyMe").keyup(function() {
$(".copyMe").val($(this).val());
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input class="copyMe" type="text" placeholder="Enter a text"/>
<input class="copyMe" type="text" />
<input class="copyMe" type="text" />
<input class="copyMe" type="text" />
这篇关于如何同步两个文本框表单值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文