[英]how to recognize select2 dropdown and select2 multiselect seperatly
i have two controls one select2 dropdown
and another jquery multi value select
我有两个控件,一个
select2 dropdown
,另一个jquery multi value select
select2 dropdown select2下拉菜单
<select id="drp_me" class="select2-offscreen">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
jquery multi value select jQuery多值选择
<select id="mult_val" class="span6 select2">
<option value="1">ONE</option>
<option value="2">TWO</option>
<option value="3">THREE</option>
</select>
but the problem is when i am passing these Ids to JS function and trying to display it's type both are showing the type as select-one
但是问题是当我将这些Ids传递给JS函数并尝试显示其类型时,两者都将该类型显示为
select-one
JS JS
$('#drp_me').select2();
$('#mult_val').multiSelect();
function displayType(id) // id = mult_val or drp_me
{
var control=document.getElementById(id);
console.log(control.type); // both controls showing as `select-one`
}
i am using jquery plugins for both controls select2
and multiSelect
. 我正在为控件
select2
和multiSelect
使用jquery插件。 basically both are same select control (select). 基本上两者都是相同的选择控件(select)。 but physically they are different.
但实际上它们是不同的。
how i can differ these controls through code??
Have you tried adding multiple='multiple'
to mult_val
? 您是否尝试过将
mult_val
multiple='multiple'
添加到mult_val
? Because from your markup they are both single-select. 因为从您的标记来看,它们都是单选的。
You should use <select multiple>
for multiselect box: 您应该对多选框使用
<select multiple>
:
<select multiple id="mult_val" class="span6 select2">
<option value="1">ONE</option>
<option value="2">TWO</option>
<option value="3">THREE</option>
</select>
You can identify the control by its IDs using "#", so for select2 you can use $('#drp_me')... and for multiselect you simply use its ID as above $('#mult_val')... 您可以使用“#”通过控件的ID来识别控件,因此对于select2而言,您可以使用$('#drp_me')...对于多选控件,您只需在$('#mult_val')以上使用控件的ID ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.