即使重新选择了相同选项,也可以运行更改事件以进行选择 [英] Run change event for select even when same option is reselected
问题描述
< select>
< option> 0< / option>
< option selected =selected> 1< / option>
< option> 2< / option>
< option> 3< / option>
< / select>
我试图编写一个即使在选择相同选项时也会被解雇的函数,打开下拉菜单并重新选择所选选项,我希望它执行该功能。
如果你的意思是用鼠标选择,你可以使用 mouseup
。然而,当选择框被打开时它也会触发,所以你需要跟踪它被触发的次数(even:select被打开,odd:select被关闭): http://jsfiddle.net/T4yUm/2/ 。
$(select)。mouseup(function(){
var open = $(this).data(isopen);
if(open ){
alert(1);
}
$(this).data(isopen,!open);
});
Basically, I have drop down menu that looks like this:
<select>
<option>0</option>
<option selected="selected">1</option>
<option>2</option>
<option>3</option>
</select>
I am trying to write a function that is fired even when you select the same option, i.e. even if the drop-down is opened and re-select the selected option, I want it to execute the function.
If you mean selecting with the mouse, you can use mouseup
. However, it will fire when the select box is being opened as well, so you'll need to keep track of the amount of times it was fired (even: select is being opened, odd: select is being closed): http://jsfiddle.net/T4yUm/2/.
$("select").mouseup(function() {
var open = $(this).data("isopen");
if(open) {
alert(1);
}
$(this).data("isopen", !open);
});
这篇关于即使重新选择了相同选项,也可以运行更改事件以进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!