鉴于下面的 HTML,我需要一个 jQuery 选择器来选择 <option>
与 with-stamp
类。
<select name="preset_select">
<option selected="selected" value="original">ORIGINAL</option>
<option value="large">LARGE</option>
<option class="with-stamp" value="medium">MEDIUM</option>
</select>
$("select[name=preset_select]").change(function() {
// console.log( $(this).hasClass("with-stamp") ); // all false
// console.log( $("select[name=preset_select] option").hasClass("with-stamp") ); // all true
});
最佳答案
$("select[name='preset_select']").change(function() {
$(this).children(':selected').hasClass('with-timestamp')
}
关于<select> 的 <option> 框的 jQuery 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4261955/