Javascript 使用multiselect select2下拉列表验证
如果在DropDown1中选择了一个选项而无法在DropDown2中选择,则必须在此处选择multiselect下拉验证Javascript 使用multiselect select2下拉列表验证,javascript,php,jquery,yii2,jquery-select2,Javascript,Php,Jquery,Yii2,Jquery Select2,如果在DropDown1中选择了一个选项而无法在DropDown2中选择,则必须在此处选择multiselect下拉验证 $("#DropDown2").change(function() { var selected = $('#DropDown1').select2("val"); var NotDropDown1Val = $('#DropDown2').val()
$("#DropDown2").change(function()
{
var selected = $('#DropDown1').select2("val");
var NotDropDown1Val = $('#DropDown2').val();
if(selected.length > 0)
{
if(NotDropDown1Val.length > 0)
{
for (var i = 0; i <= NotDropDown1Val.length-1; i++)
{
if(selected.includes(NotDropDown1Val[i]))
{
alert('Applicable and Not Applicable can not same.');
var selectedStates = $("#DropDown2").select2("val"),
index = selectedStates.indexOf(NotDropDown1Val[i]);
if (index > -1 )
{
// if NV is found, remove it from the array
selectedStates.splice(index, 1);
// and set the value of the select to the rest of the selections
$("#DropDown2").select2("val", selectedStates);
}
// alert(index);
return false;
}
}
}
}
});
$("#DropDown1").change(function()
{
var selected = $('#DropDown2').select2("val");
var DropDown1SelectVal = $('#DropDown1').val();
if(selected.length > 0)
{
if(DropDown1SelectVal.length > 0)
{
for (var i = 0; i <= DropDown1SelectVal.length-1; i++)
{
if(selected.includes(DropDown1SelectVal[i]))
{
alert('Applicable and Not Applicable can not same.');
var selectedStates = $("#DropDown1").select2("val"),
index = selectedStates.indexOf(DropDown1SelectVal[i]);
if (index > -1 )
{
// if NV is found, remove it from the array
selectedStates.splice(index, 1);
// and set the value of the select to the rest of the selections
$("#Promotion_MerID").select2("val", selectedStates);
}
// alert(index);
return false;
}
}
}
}
});