jQuery selector statement selecting a select box option tag
is there a selector for when an option selected in a select box like jQuery('select option[@sele开发者_如何学Pythoncted=....] this were im confused is it just jQuery(select > option[@selected]) and also how do you test a an option in the jQuery selector statement that it's not the first option
It would look like this (note there's no @
, this was removed in jQuery 1.3+):
jQuery("select option:selected")
If you wanted to get anything but the first, you can use :not(:first-child)
, like this:
jQuery("select option:selected:not(:first-child)")
//or...
jQuery("select option:gt(0):selected")
Though to get the value, you'd typically just want to call .val()
directly on the <select>
, like this:
jQuery("select").val()
$("select option:selected");
or
$(this, "option:selected");
test not first option
$("select option:not(eq0)"); <---I think
精彩评论