因为我在div中注册的所有事件监听器在翻转div后都不可用,所以我在翻转后再次注册这个监听器
$(document).on("click", "#element", function(){ do something});
i.e:
在我的 JSP 中: `$(document).ready(function() {
$("#register").click(function() {
switchRegister();
});
$("#forgPass").click(function() {
forgPass();
});
});`
在 .js 文件中:
/*
* 将登录界面切换至注册界面
*/
函数 switchRegister() {
var mainContent = $("#LoginBox").html();
$("#btnLogIn").prop('value', regText);
$("#regProfile").hide();
$("#regPass").hide();
$("#iconName").show();
$("#regText").show();
$("#goBack").show();
var content = $("#LoginBox").html();
$("#LoginBox").flippy({
direction:"LEFT",
duration: "500",
verso: content,
onFinish: function() {
$("#goBack").on("click", function(){
$("#LoginBox").empty();
backToLogin(mainContent, "right");
});
}
});
}
/*
* 返回登录屏幕
*/
函数 backToLogin(内容,方向) {
if(direction == "right") {
console.log("direction RIGHT");
$("#LoginBox").flippy({
direction:"RIGHT",
duration: "500",
verso: content,
onFinish: function(){
$(document).on("click", "#register", function(){
switchRegister();
});
$(document).on("click", "#forgPass", function(){
forgPass();
});
}
});
} else {
console.log(" direction Bottom");
$("#LoginBox").flippy({
direction:"BOTTOM",
duration: "500",
verso: content,
onFinish: function(){
$("#register").on("click", function(){
switchRegister();
});
$("#forgPass").on("click", function(){
forgPass();
});
}
});
}
}
/*
* 忘记密码
*/
函数 forgPass() {
var mainContent = $("#LoginBox").html();
$("#btnLogIn").prop('value', passText);
$("#regPass").hide();
$("#regProfile").hide();
$("#iconPass").hide();
$("#regText").hide();
$("#goBack").show();
var content = $("#LoginBox").html();
$("#LoginBox").flippy({
direction:"TOP",
duration: "500",
verso: content,
onFinish: function() {
$("#goBack").on("click", function(){
$("#LoginBox").empty();
backToLogin(mainContent, "bottom");
});
}
});
}