简体   繁体   English

如何使用另一个select2值选择select2

[英]how to select select2 using another select2 values

I have two select2 input boxes, My requirement is if I selected one select2 box that value will effect with another select2 box. 我有两个select2输入框,我的要求是,如果我选择一个select2框,则该值将与另一个select2框一起生效。

my code is as below: 我的代码如下:

<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>

please tell me where I did mistake? 请告诉我我在哪里做错了?

Thanks, Madhuri 谢谢,Madhuri

You mean the value in both boxes should be same, right? 您是说两个框中的值都应该相同,对吗?

$(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
    });
});

DEMO DEMO

这是您要找的吗?

 $('.unitId_0').val("hr");

you can do this like,it should work. 你可以这样做,它应该可以工作。

var a=$(".itemid_0").val();
$('.unitId_0').val(a);

you can use keyup or onclick events 您可以使用keyuponclick事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM