简体   繁体   English

我怎么知道用户是否在选择框中选择了相同的项目

[英]How can I know if the user selected the same item in a select box

I have a select box that needs to act even if the user selects the currently selected item. 我有一个选择框,即使用户选择了当前选中的项目,也需要采取行动。 I have used onChange (via JQuery) but it doesn't fire if the same item is selected because it hasn't changed. 我已经使用过onChange(通过JQuery),但是如果选择了同一项,则不会触发,因为它没有更改。

Is this even possible? 这有可能吗?

I'm not sure i understand your question clearly cause of my English. 我不确定我是否清楚您的问题是我英语的原因。 You want to know when a checkbox is clicked if it is already checked you want to fire a function. 您想知道何时单击一个复选框(如果它已被选中)是否要触发功能。 If i'm right then you can do it in many ways. 如果我是对的,那么您可以通过多种方式做到这一点。 Eg If you have 2 classes for your checkbox checked or unchecked you can look if that checkbox got "checked" class with .hasClass or you can store index of a checkbox in an array when it is clicked, and every click on a checkbox you can search array if that array has index of that checkbox. 例如,如果您的复选框有2个类处于选中状态或未选中状态,则可以查看该复选框是否具有.hasClass类的“选中”类,或者可以在单击复选框时将其索引存储在数组中,并且每次单击复选框都可以搜索该数组是否具有该复选框的索引。 If result is true, you fire your function. 如果结果为true,则触发函数。

You can try in each of your select box to include the onclick event and call your desired function when that happens. 您可以尝试在每个选择框中包括onclick事件,并在发生这种情况时调用所需的函数。 Or you can use the onblur event in your element and fire your function when that happens. 或者,您可以在元素中使用onblur事件,并在发生这种情况时触发函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何添加效果以了解列表中的选定项目 - How can I add an effect to know the selected item in list 如何滚动到选择框中的所选项目 - How to scroll to selected item in a select box 如何获取select框中选中的item的position - How to get the position of selected item in the select box 如何知道选择框中的可用选项何时更改 - How can I know when the available options in a select box changes 如何制作一个用href选中的选择框? - How to can I make a select box that is selected with href? 我如何知道在选择框中选择了哪个对象,或者有可能将对象绑定到KnockoutJS视图模型? - How do I know which object was selected in a select box or is it possible to bind an object to the KnockoutJS view model? 如何检查用户是否通过 jQuery selectable 选择了一个项目? - How can I check if a user selected an item via jQuery selectable? 选择选择框中的任何项目时,如何在jQuery中触发事件? - How do I trigger a event in jQuery when any item in a select box is selected? 如何根据“选择”框中的项目选择提供所选属性? - How do I give the selected properties according to the item selection in the Select box? 如何根据文本框中的用户输入更改下拉列表中的选定项目? - How do I change the selected item in a dropdown based on user input in a text box?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM