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('');
}
});
精彩评论