listen on Enter key press event
This commit is contained in:
parent
079e0d3de9
commit
25233d09ff
@ -2,36 +2,27 @@
|
||||
* @Author: prpr
|
||||
* @Date: 2016-01-21 13:55:44
|
||||
* @Last Modified by: prpr
|
||||
* @Last Modified time: 2016-02-03 20:38:41
|
||||
* @Last Modified time: 2016-02-03 21:40:41
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
$('#login').click(function(){
|
||||
$('[data-remodal-id=login-modal]').remodal().open();
|
||||
})
|
||||
|
||||
$('#register').click(function(){
|
||||
$('[data-remodal-id=register-modal]').remodal().open();
|
||||
})
|
||||
|
||||
// Login Button Click Event
|
||||
$("body").on("click", "#login-button", function(){
|
||||
var login = function() {
|
||||
var uname = $("#uname").val();
|
||||
var passwd = $("#passwd").val();
|
||||
if (checkForm("login", uname, passwd)) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "ajax.php?action=login",
|
||||
dataType: "json",
|
||||
data: {"uname":uname,"passwd":passwd},
|
||||
beforeSend: function() {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "ajax.php?action=login",
|
||||
dataType: "json",
|
||||
data: { "uname": uname, "passwd": passwd },
|
||||
beforeSend: function() {
|
||||
showMsg("alert-info", "Logging in...");
|
||||
},
|
||||
success: function(json) {
|
||||
if (json.errno == 0) {
|
||||
docCookies.setItem("uname", uname, null, '/');
|
||||
docCookies.setItem("token", json.token, null, '/');
|
||||
success: function(json) {
|
||||
if (json.errno == 0) {
|
||||
docCookies.setItem("uname", uname, null, '/');
|
||||
docCookies.setItem("token", json.token, null, '/');
|
||||
if ($("#keep").prop("checked")) {
|
||||
docCookies.setItem("uname", uname, 604800, '/');
|
||||
// 设置长效 token (7天)
|
||||
@ -43,13 +34,12 @@ $("body").on("click", "#login-button", function(){
|
||||
showAlert(json.msg);
|
||||
showMsg('hide', "");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Register Button Click Event
|
||||
$("body").on("click", "#register-button", function(){
|
||||
var register = function() {
|
||||
var uname = $("#reg-uname").val();
|
||||
var passwd = $("#reg-passwd").val();
|
||||
if (checkForm("register", uname, passwd, $("#reg-passwd2").val())) {
|
||||
@ -75,7 +65,7 @@ $("body").on("click", "#register-button", function(){
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkForm(type, uname, passwd, passwd2) {
|
||||
switch(type) {
|
||||
@ -117,3 +107,21 @@ function checkForm(type, uname, passwd, passwd2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$('#login').click(function(){
|
||||
$('[data-remodal-id=login-modal]').remodal().open();
|
||||
})
|
||||
|
||||
$('#register').click(function(){
|
||||
$('[data-remodal-id=register-modal]').remodal().open();
|
||||
})
|
||||
|
||||
// Register Event
|
||||
$("body").on("keypress", "[data-remodal-id=register-modal]", function(event){
|
||||
if (event.which == 13) register();
|
||||
}).on("click", "#register-button", register);
|
||||
|
||||
// Login Event
|
||||
$("body").on("keypress", "[data-remodal-id=login-modal]", function(event){
|
||||
if (event.which == 13) login();
|
||||
}).on("click", "#login-button", login);
|
||||
|
Loading…
Reference in New Issue
Block a user