开发者

select option doesn't work in IE and SAFARI

the following code doesn't work in IE and Safari but works fine in firefox.

$('select#colors option').click开发者_StackOverflow(function() {
   //this is for testing but I get no alert in IE and Safari 
   alert('item selected');
}); 


<select id="colors" class="select">
     <option>Please select your style</option>
     <option>Navy</option>
     <option>Grey</option>
     <option>Black</option>
</select>

any ideas!!


Try this one instead

$('select#colors').bind('change', function() {
  alert('selected item changed');
}); 


You need to attach the function to the select rather than each option:

$('select#colors').click(function() {
   alert('item selected: ' + $(this).val());
}); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜