jQuery选择器的盒子

前端之家收集整理的这篇文章主要介绍了jQuery选择器的盒子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
给定下面的HTML,我需要一个jQuery选择器来选择< option>与邮票类.
<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')
}
原文链接:https://www.f2er.com/jquery/180560.html

猜你在找的jQuery相关文章