jQuery UI MultiSelect小部件-从MultiSelect下拉列表中的optgroup选项中仅选择一个
我像这样摔倒了jQuery UI MultiSelect小部件-从MultiSelect下拉列表中的optgroup选项中仅选择一个,jquery,html,jquery-ui,jquery-plugins,Jquery,Html,Jquery Ui,Jquery Plugins,我像这样摔倒了 <select multiple="multiple"> <optgroup label='name1'> <option value="1">First</option> <option value="2">Second</option> <option value="3">Third</option> </optgroup> &
<select multiple="multiple">
<optgroup label='name1'>
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</optgroup>
<optgroup label='name2'>
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</optgroup>
第一
第二
第三
第一
第二
第三
Iam使用jQuery UI MultiSelect小部件插件进行多下拉,但我应该从每个optgroup选项中只选择一个选项
例如,如果为'name1'选择了选项“First”,则不应为'name1'选项组选项选择“second”、“third”。尝试此操作
var memoryOne;
var memoryTwo;
$("option").mouseover(function () {
var selectedOne = $("optgroup:nth-of-type(1)").children("option:selected").index();
var selectedTwo = $("optgroup:nth-of-type(2)").children("option:selected").index();
memoryOne = selectedOne;
memoryTwo = selectedTwo;
}).click(function () {
var theSelectedIndex = $(this).index();
var theParentIndex = $(this).parent().index();
setTimeout(function () {
clickEvent(theSelectedIndex, theParentIndex, memoryOne, memoryTwo);
}, 1);
});
function clickEvent(passedIndex, parentIndex, memoryOne, memoryTwo) {
var selectionOne = memoryOne;
var selectionTwo = memoryTwo;
var theParent = $("optgroup:eq(" + parentIndex + ")");
var theOption = $("optgroup:eq(" + parentIndex + ") option:eq(" + passedIndex + ")");
var theGrandParent = $("select");
theParent.find("option:not(option:eq(" + passedIndex + "))").prop("selected", false);
if (parentIndex == 0) {
$("optgroup:not(optgroup:eq(" + parentIndex + "))").children("option:eq(" + selectionTwo + ")").prop("selected", true);
} else if (parentIndex == 1) {
$("optgroup:not(optgroup:eq(" + parentIndex + "))").children("option:eq(" + selectionOne + ")").prop("selected", true);
}
}
Make a你能用小提琴演奏这段代码吗。