[英]jQuery validator and bootstrap.js - Notifications/Errors
我正在為單個頁面站點探索jQuery和bootstrap.js。 如果不擅長使用復雜的CSS和jQuery,這可能會有些麻煩。 我的目標是在他們的英雄盒示例上輕松構建,該示例在右上角有一個登錄表單,如下所示: http : //twitter.github.com/bootstrap/examples/hero.html
我有一個用於創建用戶的工作表,在此示例中使用了此示例: http : //alittlecode.com/files/jQuery-Validate-Demo/
目標是將其與類似以下通知/警報的內容組合: http : //www.w3resource.com/twitter-bootstrap/alerts-and-errors-tutorial.php
我有相關的部分是:
$(document).ready(function(){
$.validator.addMethod('validChars', function (value) {
var iChars = "!#$%^&*()+=-[]\\\';,/{}|\":<>?";
for (var i = 0; i < value.length; i++) {
if (iChars.indexOf(value.charAt(i)) != -1) {
return false;
}
}
return true;
});
$('#login_form').validate(
{
rules: {
login_email: {
required: true,
validChars:true,
maxlength:50
},
login_password: {
validChars:true,
required: true
}
},
highlight: function(input) {
$(input).closest('.control-group').addClass('error');
},
unhighlight: function(input) {
$(input).closest('.control-group').addClass('success');
}
});
});
我的表格如下所示:
<form id="login_form" name="login_form"; class="navbar-form pull-right control-group" action="">
<input class="span2 control-group" placeholder="Email" name="login_email" id="login_email">
<input class="span2 control-group" placeholder="Password" name="login_password" id="login_password">
<button class="btn login" type="button" onclick="login();">Sign in</button>
<button class="btn requestor" type="button" onclick="createForm();" >Create new account</button>
</form>
什么都沒發生,我真的沒有主意。
通知或事件的雄心是說明性的,我主要關心的是將驗證與表單聯系起來。
先感謝您!
問題是您沒有提供<input>
'sa類型。 當它們沒有類型時,validate無法處理輸入。
Validate像這樣評估輸入字段
.validateDelegate("[type='text'], [type='password'], [type='file'], select, textarea, " +
"[type='number'], [type='search'] ,[type='tel'], [type='url'], " +
"[type='email'], [type='datetime'], [type='date'], [type='month'], " +
"[type='week'], [type='time'], [type='datetime-local'], " +
"[type='range'], [type='color'] ",
"focusin focusout keyup", delegate)
沒有類型的輸入不包括在內。 因此
<input type="text" class="span2 control-group" placeholder="Email" name="login_email" id="login_email">
<input type="text" class="span2 control-group" placeholder="Password" name="login_password" id="login_password">
會成功的!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.