Javascript 如何使用另一个select2值选择select2
我有两个select2输入框,我的要求是,如果我选择了一个select2框,该值将与另一个select2框一起生效 我的代码如下:Javascript 如何使用另一个select2值选择select2,javascript,jquery,jquery-select2,Javascript,Jquery,Jquery Select2,我有两个select2输入框,我的要求是,如果我选择了一个select2框,该值将与另一个select2框一起生效 我的代码如下: <input class="select2-offscreen itemid_0" type="text" name="itemid" id="itemid[]" style="width:100px; left:297.5px !important; top:863px !important; float:left !important" tabindex=
<input class="select2-offscreen itemid_0" type="text" name="itemid" id="itemid[]" style="width:100px; left:297.5px !important; top:863px !important; float:left !important" tabindex="-1" onchange="display();">
<input class="select2-offscreen unitId_0" type="text" name="unitId" id="unitId[]" style="width:100px; left:297.5px !important; top:863px !important; float:left !important" tabindex="-1">
<script>
function display(){
$(".unitId_0").select2("val","hr");
}
</script>
函数显示(){
$(“.unitId_0”)。选择2(“val”、“hr”);
}
请告诉我哪里出错了
谢谢,
马杜里你要找的就是这个吗
$('.unitId_0').val("hr");
你的意思是两个框中的值应该相同,对吗
$(function () {
$(".itemid_0").keyup(function () { // on key up in first box
var value = $(this).val(); // get its value
$(".unitId_0").val(value); // set the value of the second box to it
});
});
你可以这样做,它应该可以工作
var a=$(".itemid_0").val();
$('.unitId_0').val(a);
你可以使用
keyup
或onclick
events你到底想要实现什么?你所说的效果是什么意思?我需要在选择的2个单位中显示值你可以在下面查看我的更新答案,