0
工作,我想驗證使用佔位符在IE7 + 8佔位符在IE與jQuery的驗證
我使用的有效()調用從驗證的jQuery插件我的HTML 5的形式。這意味着我不能使用這個解決方案:placeholder issue with jQuery Validate。雖然我的問題是相同的。我使用的佔位符腳本將佔位符文本添加到值屬性中。當調用驗證時,腳本將佔位符文本讀取爲有效輸入。
我不做全面驗證,因爲表單分佈在多個「選項卡」中,因此需要在下一節顯示之前進行驗證。這是不可negotionalble
我的佔位符腳本:
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur();
$('[placeholder]').parents('form').submit(function() {
$(this).find('[placeholder]').each(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
}
})
});
和這裏就是我所說的驗證:
if (elements.valid() === 0) {
valid = 0;
}
if (valid) {
$('.form').removeClass('error');
$(this).closest('section').hide().next().show();
}
任何幫助將不勝感激!
嘗試[驗證佔位符的通用方法] [1] [1]:http://stackoverflow.com/a/15898568/657357 – Hogan 2013-04-09 10:18:19