Jquery and IE 7 - selected property not working for multiple select boxes, even when options are selected
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.
精彩评论