app.controller('myRegister',['$scope',function($scope){
(function(){
"use strict";
var form=document.forms['form'];
var userName=form.uname;
var pwd=form.upwd;
var btn=form.elements[form.length-1];
userName.onfocus=getFocus;
pwd.onfocus=getFocus ;
userName.onblur=function(){
vali(this,/^(\+86|0086)?\s*1[34578]\d{9}$/);
}
pwd.onblur=function(){
vali(this,/^[\w\.\-\+]{6,16}$/);
}
function getFocus(){
this.style.background="#EFEFEF";
}
function vali(txt,reg){
/*获取下一个兄弟元素,验证失败样式*/
var p=txt.nextElementSibling;
if(reg.test(txt.value)){
txt.style.borderColor="#A4DC3E";
p.className='';
return true;
}else{
txt.style.borderColor="red";
p.className='vali_fail';
return false;
}
}
btn.onclick=function(){
if(!vali(userName,/^(\+86|0086)?\s*1[34578]\d{9}$/)){
userName.focus();
console.log(userName);
}else if(!vali(pwd,/^[\w\.\-\+]{6,16}$/)){
pwd.focus();
console.log(pwd);
} else{
form.submit();
}
}
})()
}]);
写的样式都可以显示,也没有报错,就是无法获得鼠标焦点
会不会和你的控件有关系?