开发者

JQuery: choose drop down from list of selected inputs

开发者 https://www.devze.com 2023-03-12 08:53 出处:网络
So I have this code: jQuery(\'div[class=\"someClass\"] :input:not(:button)\').each(functi开发者_如何学Pythonon() {

So I have this code:

jQuery('div[class="someClass"] :input:not(:button)').each(functi开发者_如何学Pythonon() {               
    if (input type is drop-down) {
        //do something
    }
    else {
        jQuery(this).attr("value",null);
    }
}

I have selected all inputs except buttons in a specific class. Now for each input selected, if the input is a drop-down list I wish to do something, otherwise I wish to set the input to blank, which the last line does. How can this be accomplished?


You could use the is() method:

if ($(this).is('select')) {
    //do something
} else {
    $(this).val('');
}


Should ignore all input type button and button elements.

$('.someClass').each(function(){
    if ($(this).is('select')) {
        //do something
    } else if ($(this).not('input[type="button"]') && $(this).not(':button')){
        $(this).val('');
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消