$('input[name=password]').bind('keypress',function(event){ if(event.keyCode == "13") adminLogin(); }); $('.nomargin').click(function () { adminLogin(); }) function adminLogin() { var u_phone = $.trim($("input[name=u_phone]").val()); var password = $.trim($("input[name=password]").val()); var requestUrl = $.trim($("input[name=requestUrl]").val()); if(u_phone == ''){ layer.msg('手机不能为空', {icon: 2, time: 2000}); return; } if (u_phone.length != 11 || !(/^1[3|4|5|7|8]\d{9}$/.test(u_phone))) { layer.msg('手机号码非法的', {icon: 2, time: 2000}); return; } if(password == ''){ layer.msg('密码不能为空', {icon: 2, time: 2000}); return; } $.ajax({ type: "POST", url: '/login/', dataType: 'json', cache: false, data: {u_phone:u_phone,password:password,requestUrl:requestUrl}, success: function (data) { if (data.status < 1) { layer.msg(data.msg, {icon: 2, time: 2000}); return; } if(data.user_token){ localStorage.setItem('08_user_token',data.user_token); } layer.msg(data.msg, {icon: 1, time: 1000}, function () { location.href = data.requestUrl; }); }, error: function (xhr) { layer.msg(xhr.errors[0], {icon: 2, time: 2000}); } }); }