核心代码
复制代码 代码如下:
$(document).ready(function(){
$(按下回车的控件).keydown(function(e){
var curkey = e.which;
if(curkey == 13){
$(#回车事件按钮控件).click();
return false;
}
});
});
是用js的ajax功能同时支持回车事件
复制代码 代码如下:
document.onkeydown = function (e) {
var theevent = window.event || e;
var code = theevent.keycode || theevent.which;
if (code == 13) {
$(#login_submit).click();
}
}
$(document).ready(function() {
//登录提交
$(#login_submit).bind('click',function(){
var username=$(#username).val();
var password=$(#password).val();
$.ajax({
type : 'post',
url : './login.php',
data: {type :'ajax',username:username,password:password},
success : function(msg){
//alert(msg);
if(msg==-1){
alert('用户名不能为空');
$(#username).focus();
}
if(msg==-2){
alert('用户名不存在');
$(#username).val();
$(#username).focus();
}
if(msg==-3){
alert('密码不能为空');
$(#password).focus();
}
if(msg==-6){
alert('密码输入不正确');
$(#password).focus();
}
if(msg==1){
//alert('登录成功');
window.location.href='./index.php';
}
}
});
});
});
