문제

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? This is the screen shots of the controls

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top