简体   繁体   中英

types of jquery chosen and select2 multiselect

i have two controls one chosen multiselect and another select2 multivalue select

chosen multiselect

<select id="mlti_1" class="chosen span6" multiple='multiple' >
  <option value="1">one</option>
  <option value="2">two</option>
  <option value="3">three</option>
</select>

jquery multi value select

<select id="mult_2" class="select2 span6" multiple='multiple'>
  <option value="1">ONE</option>
  <option value="2">TWO</option>
  <option value="3">THREE</option>
</select>

both controls are working fine, 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-multiple

JS

//no need to initiate chosen multiselect
$('#mult_2').multiSelect(); // initiating select2 multiselect
function displayType(id) // id = mult_val or drp_me
{
  var control=document.getElementById(id);
  console.log(control.type); // both controls showing as select-multiple
}

i am using jquery plugins for both controls. basically both are same select control (select). but physically they are different. how i can differ these controls through code?? is there any solution for this? 这是控件的屏幕截图

By differ if you meant accessing them and their values using different handles, you can do that just by accessing their ids.

use $("#mlti_1") for accessing the chosen control and $("#mult_2") for the second multiselect control.

UPDATE :

As I said in the comment, you can use the following function to determine the type of the multi-select.

function displayType(id) // id = mult_val or drp_me
{
    var control = document.getElementById(id);
    console.log(control.type); // both controls showing as select-multiple
    if (control.classList.contains("chosen")) {
        console.log("chosen");
    } else if (control.classList.contains("select2")) {
        console.log("select2");
    }
}

provided, you assign proper class names(chosen and select2) to the various multi-selects in the HTML code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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