我目前正在閱讀jQuery和我米麪臨jQuery功能上的一些問題..任何人可以指導我關於功能。目前我只想創建一個函數,每次調用兩次,如果需求相同..但函數不工作請專家指導我在代碼中。jquery功能不工作
var errorAlpha = function(){
$(this).focus().keyup(function(){
var reg = /^([A-Za-z]+)$/;
var check = $(this).val();
if(reg.test(check)==true && check.match(reg)==true)
{
$(this).removeClass('error_Aplha');
}
else {
$(this).addClass('error_Aplha');
}
}),blur(function(){
var check = $(this).val();
var reg = /^([A-Za-z]+)$/;
if(reg.test(check)==true && check.match(reg)==true)
{
$(this).removeClass('error_Aplha');
}
else {
$(this).addClass('error_Aplha');
}
});
};
$('#step1 #fName').function(errorAlpha());
HTML是這裏
<input type="text" class="width-260" id="fName"/>
CSS是這裏
.error_Aplha {
border:1px solid #b20000 !important;
box-shadow: 0px 0px 5px #b20000;
-webkit-box-shadow: 0px 0px 5px #b20000;
-moz-box-shadow: 0px 0px 5px #b20000;
}
你有一個語法錯誤'}),blur'。調試代碼是尋找錯誤的第一步。正確縮進代碼也有幫助。 – elclanrs