2010-06-08 70 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:儘管如此,他是不是也想'