开发者

Jquery and IE 7 - selected property not working for multiple select boxes, even when options are selected

开发者 https://www.devze.com 2023-01-22 09:33 出处:网络
I\'ve a dropdown (开发者_如何学Cmultiple select).I choose a few values, they are highlighted correctly, but jQuery doesn\'t recognize them as selected.this works in firefox and chrome, doesn\'t work i

I've a dropdown (开发者_如何学Cmultiple select). I choose a few values, they are highlighted correctly, but jQuery doesn't recognize them as selected. this works in firefox and chrome, doesn't work in IE. this is the code

$("#myBox" +" option").each(function() 
{
  if ($(this).attr("selected") == true) 
  {
     // do something
  }
}


try this:

$("select").each(function(){

    $(this).children("option:selected").each(function(){

       //handle this $(this).val()

    });                 
});

works fine for me =]


have you tried

$("#myBox option:selected").each(function(){
   //do something
});

This is I usually handle select boxes and this seems to work well for me.

0

精彩评论

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

关注公众号