开发者

JQuery: choose drop down from list of selected inputs

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜