2012-03-06 88 views
-2
if(hasWhiteSpace($(this).find(".nospace:input").val())){ 
    $(this).find(".nospace:input").filter(function() { 
     return hasWhiteSpace(this.value) == true; 
    }).addClass("blank"); 
    setError(".motd_register_company","There must be no space in between."); 
    return false; 
} 

上面的代碼有些問題,代碼只驗證第一個輸入,而其他代碼不驗證,我如何驗證所有在我的表單中的「nospace」類?如何使用.find()或某些jQuery語法來查找某個類?

如果出現問題,你們可以修改我的代碼嗎?

+4

你的問題就沒有意義了。 – 2012-03-06 18:06:29

+0

@MДΓΓБДLL對不起... – daison12006013 2012-03-06 18:11:46

+0

使用jsfiddle給我們看看。 – mozillanerd 2012-03-06 18:12:27

回答

2

您是否試圖遞歸搜索特定類名的元素?如果是這樣的:

$('input.class_name').each(function() { 
    // Do you stuff to this input element 
}); 
1
jQuery.each("input.nospace", function(i, el){ 
    var self = $(el); 

    if(hasWhiteSpace(self.val()) self.addClass("blank"); 

}); 
相關問題