检测下拉开启 [英] Detect drop down openes
本文介绍了检测下拉开启的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法(在简单的JS或jQuery中)确切地检测到那个时刻,下拉(select-tag)打开了?为了澄清更多,一个小例子:
Is there any way (in plain JS or jQuery) to detetect exactly that moment, a drop down (select-tag) opens? To clarify more, a small example:
如果您在选择上单击5次,则会发生以下情况:
If you click 5 times on a select, the following happens:
drop down opens > Event should fire
drop down closes
drop down opens > Event should fire
drop down closes
drop down opens > Event should fire
到目前为止,我只能找到点击/焦点/焦点的事件。
So far, I just can find events for the click/focus in/focus out.
推荐答案
看看这段代码:
HTML:
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.2.min.js">
</script>
<select id="fire">
<option>One</option>
<option>Two</option>
</select>
<p></p>
JQuery:
var flag=1;
$("#fire").click(function(){
if(flag==1){
$("p").append("clicked ");
flag=0;
} else {
flag=1;
}
});
$("#fire").blur(function(){
flag=1;
});
这篇关于检测下拉开启的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文