[英]how to select select2 using another select2 values
我有兩個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>
請告訴我我在哪里做錯了?
謝謝,Madhuri
您是說兩個框中的值都應該相同,對嗎?
$(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
事件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.