我正在探索單個頁面站點的jQuery和bootstrap.js。如果在複雜的CSS和jQuery中不夠強大,這可能會有點麻煩。我的目標是在他們的英雄盒例如簡單的建築,它在右上角的登錄形式,在這裏看到:http://twitter.github.com/bootstrap/examples/hero.htmljQuery驗證和bootstrap.js - 通知/錯誤
我有一個工作形式,創建用戶,在這裏我用這個例子: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>
一點都沒有發生,我真的沒有想法。
通知或事件的野心是說明性的,我主要關心的是驗證與表單相關。
預先感謝您!
你有什麼錯誤嗎? –
零錯誤,遺憾離開了。麻煩的是驗證器不處理表單。高光/不高光永遠不會被調用。 –