2010-06-08 71 views
9

我有一个表格,我明确了重点。我选择了整个表单,除了点击时提交按钮变为空白以外,它的效果很好。Jquery排除选择器?

我怎么能排除我的输入输入#从下面的代码提交?

$(".wpcf7-form input, .wpcf7-form textarea").focus(function() { 
if(this.value == this.defaultValue) { 
    this.value = ""; 
    $(this).addClass('filled'); 
} 
}).blur(function() { 
if(!this.value.length) { 
    this.value = this.defaultValue; 
    $(this).removeClass('filled'); 
} 
}); 

回答

9

使用not选择排除你想要什么:

$(".wpcf7-form input:not('#submit_id'), .wpcf7-form textarea").focus(function() { 
// your code...... 
} 

或者

$(".wpcf7-form input:not(input[type=submit]), .wpcf7-form textarea").focus(function() { 
// your code...... 
} 
1
$(".wpcf7-form input:not(#submit), .wpcf7-form textarea") 

not

+1

更简单:'$( “wpcf7形式:输入:否(#submit)”)作为'':input'包括'textarea'。 – 2010-06-08 21:13:20

+0

@Tatu Ulmanen:尽管如此,他是不是也想'