2011-10-29 61 views
2

在Firefox中,當我點擊選項,Firefox的問候選擇也被點擊。 e.stoppropgation()或e.preventdefault()不能解決此問題。是否有可能停止選項點擊事件就像在鉻?謝謝你的想法。jQuery選擇點擊和火狐

<select> 
<option>test</option> 
</select> 
<p>adfadf</p> 
$(document).ready(function(){ 
$("select").click(function(){$("p").toggle();}) 
$("select option").click(function(){alert('it is weired');}) 
}) 

回答

2
$("select").click(function(){ 
     console.log('select'); 
     $("p").toggle(); 
}); 

$("select option").click(function(e){ 
    e.stopPropagation(); 
    console.log('it is not weired'); 
}); 

http://jsfiddle.net/GzNuf/

+0

是的,謝謝。我拼錯停止傳播。非常非常愚蠢。 – user995789

1

請勿使用點擊事件。使用更改事件。 Firefox正在做對,你正在點擊選擇框。

1

「點擊」不是select元素的適當事件。您應該使用change