用于在启用了多个属性的选择菜单中取消选择项目的事件处理程序

发布于 2024-11-15 08:45:59 字数 325 浏览 3 评论 0原文

我正在使用一个选择菜单,它允许进行多项选择。我有一个事件处理程序

 $("#idInventory").change(function () {
     $("#select option:selected").each(function () {
    });
});

,当选择一个项目时会调用该事件处理程序。我在这里收集了所有选择的项目。但我还需要知道每个选定的项目何时被取消选择,以便我可以跟踪取消选择的内容,以便我可以跟踪用户现在是否取消选择已选择的项目。

更新:当取消选择某个项目时,我没有触发此事件。

I am using a select menu which will allow multiple selections to be done. I have an event handler

 $("#idInventory").change(function () {
     $("#select option:selected").each(function () {
    });
});

which is called when an item is selected. Here I collect what ever items are chosen . But I also need to know when each selected item is deselected so that I can track what is deselected so that I can keep track if something already chosen is now deselected by user.

UPDATE: I am not getting this event triggered when an item is deselected.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻找我们的幸福 2024-11-22 08:45:59

我认为这就是您可能正在寻找的:

有点工作演示:

HTML

<div data-role="page" data-theme="b" id="home"> 
    <div data-role="content">

        <div data-role="fieldcontain"> 
            <label for="select-choice-9" class="select">Choose shipping method(s):</label> 
            <select name="select-choice-9" id="select-choice-9" multiple="multiple" data-native-menu="false"> 
                <option>Choose options</option> 
                <option value="standard">Standard: 7 day</option> 
                <option value="rush">Rush: 3 days</option> 
                <option value="express">Express: next day</option> 
                <option value="overnight">Overnight</option> 
            </select> 
        </div>

    </div>
</div>

JS

var values = {
    selected: [],
    unselected:[]
};

$("#select-choice-9").change(function () {
    values.selected   = [];
    values.unselected = [];

    $("#select-choice-9 option").each(function(){
        values[this.selected ? 'selected' : 'unselected'].push(this.value);
    });

    alert('Selected: '+values.selected+' Unselected: '+values.unselected);
});

更新:

$("#select-choice-9").change(function () {
    values.selected   = [];
    values.unselected = [];

    $("#select-choice-9 option").each(function(){
        values[this.selected ? 'selected' : 'unselected'].push(this.value);
    });

    alert('Selected: '+values.selected+' Unselected: '+values.unselected);
}).page();

更新#2

$("#select-choice-9").change(function () {
    values.selected   = [];
    values.unselected = [];

    $("#select-choice-9 option").each(function(){
        values[this.selected ? 'selected' : 'unselected'].push(this.value);
    });

    alert('Selected: '+values.selected+' Unselected: '+values.unselected);
}).checkboxradio("refresh");

I think this is what you might be looking for:

Kinda working demo:

HTML

<div data-role="page" data-theme="b" id="home"> 
    <div data-role="content">

        <div data-role="fieldcontain"> 
            <label for="select-choice-9" class="select">Choose shipping method(s):</label> 
            <select name="select-choice-9" id="select-choice-9" multiple="multiple" data-native-menu="false"> 
                <option>Choose options</option> 
                <option value="standard">Standard: 7 day</option> 
                <option value="rush">Rush: 3 days</option> 
                <option value="express">Express: next day</option> 
                <option value="overnight">Overnight</option> 
            </select> 
        </div>

    </div>
</div>

JS

var values = {
    selected: [],
    unselected:[]
};

$("#select-choice-9").change(function () {
    values.selected   = [];
    values.unselected = [];

    $("#select-choice-9 option").each(function(){
        values[this.selected ? 'selected' : 'unselected'].push(this.value);
    });

    alert('Selected: '+values.selected+' Unselected: '+values.unselected);
});

UPDATE:

$("#select-choice-9").change(function () {
    values.selected   = [];
    values.unselected = [];

    $("#select-choice-9 option").each(function(){
        values[this.selected ? 'selected' : 'unselected'].push(this.value);
    });

    alert('Selected: '+values.selected+' Unselected: '+values.unselected);
}).page();

UPDATE #2

$("#select-choice-9").change(function () {
    values.selected   = [];
    values.unselected = [];

    $("#select-choice-9 option").each(function(){
        values[this.selected ? 'selected' : 'unselected'].push(this.value);
    });

    alert('Selected: '+values.selected+' Unselected: '+values.unselected);
}).checkboxradio("refresh");
戴着白色围巾的女孩 2024-11-22 08:45:59
$("option").click(function(){
    if(this.selected)
      //do what you want to do
});
$("option").click(function(){
    if(this.selected)
      //do what you want to do
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文