Given the HTML below, I need a jQuery selector that selects the <option> with the with-stamp class.
<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("wit开发者_Python百科h-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')
}
You need to check only the :selected <option> (since .hasClass() returns true if any of the elements in the set have the class), like this:
$("select[name=preset_select] option:selected").hasClass("with-stamp")
$("select[name=preset_select] option:selected").hasClass('with-stamp').change(function() { 
}); 
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论