我有两个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="-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>
请告诉我我错在哪里了?谢谢,玛杜丽
您的意思是两个框中的值应该相同,对吗?
$(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
});
});
演示这是你要找的吗?
$('.unitId_0').val("hr");
你可以这样做,它应该工作。
var a=$(".itemid_0").val();
$('.unitId_0').val(a);
您可以使用keyup
或onclick
事件