我有选择框和两 (2) 个文本框。
我想要显示在第一个文本框中的选择框的值,以及它也显示在第二个框中的第一个文本框的值。
选择框 = 第一个文本框 第一个文本框 = 第二个文本框
购买方式我的第一个文本框是只读的,因此无法触发输入、keyup、keydown 事件。我希望我的两 (2) 个文本框每次都具有相同的值。
我有html代码。
<select id="selectbox">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input id="first-textbox" type="text" readonly>
<input id="second-textbox type="text">
最佳答案
I want the value of select box that displays on the first textbox and whatever the value of the first textbox it display also in the second box.
select box = first textbox first textbox = second textbox
尝试使用选择器 $("#selectbox, :text:not([readonly])")
; 输入
,更改
事件; .val()
设置两个 input type="text"
值
$("#selectbox, :text:not([readonly])").on("input change", function(e) {
$(":text").val(this.value)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<select id="selectbox">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input id="first-textbox" type="text" readonly>
<input id="second-textbox type="text">
关于javascript - jquery 中两个文本框的值相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32238975/