0

我有两个控件一个chosen multiselect和另一个select2 multivalue select

选择多选

<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多值选择

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

两个控件都工作正常,但问题是当我将这些 Ids 传递给 JS 函数并尝试显示它的类型时,两者都将类型显示为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
}

我正在为这两个控件使用 jquery 插件。基本上两者都是相同的选择控件(选择)。但在物理上它们是不同的。how i can differ these controls through code?? is there any solution for this? 这是控件的屏幕截图

4

1 回答 1

1

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.

于 2014-03-04T11:35:22.560 回答