$('#.login.button').click(function() {和
$('#.register.button').click(function() {这两个都是做事情的,我该如何在单击或回车时在它们下面运行脚本?
这是我的.js jQuery:
$(document).ready(function() {
$('#.login.button').click(function() {
// Getting the variable's value from a link
var loginBox = $(this).attr('href');
//Fade in the Popup and add close button
$(loginBox).fadeIn(300);
//Set the center alignment padding + border
var popMargTop = ($(loginBox).height() + 24) / 2;
var popMargLeft = ($(loginBox).width() + 24) / 2;
$(loginBox).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
// Add the mask to body
$('body').append('<div id="mask"></div>');
$('#mask').fadeIn(300);
return false;
});
// When clicking on the button close or the mask layer the popup closed
$('a.close, #mask').live('click', function() {
$('#mask , .login-popup').fadeOut(300 , function() {
$('#mask').remove();
});
return false;
});
$("#.sign-in.button").click(function() {
var empty = $(this).parent().find("input").filter(function() {
return this.value === "";
});
if(empty.length) {
var notification = noty({text: "Error: Some fields were not filled out" , type:"error", timeout: 2500, layout:"topCenter"});
return false;
}
var username = $('#username').val(),
password = $('#password').val();
$.ajax({
url: "components/login.php",
data:{username:username, password:password},
type: "post",
success: function(data) {
if(data == 'success') {
var notification = noty({text: "Welcome, "+username+"!" , type:"success", timeout: 2500, layout:"topCenter"});
setTimeout(function(){
window.location = document.URL;
}, 3000);}
else {
var notification = noty({text: "Error: Incorrect Username/Password" , type:"error", timeout: 2500, layout:"topCenter"});
}
},
error: function(html) {
alert('error');
},
statusCode: {
404: function() {
//404 here
}
}
});
return false;
});
$('#.register.button').click(function() {
var registerBox = $(this).attr('href');
$(registerBox).fadeIn(300);
//Set the center alignment padding + border
var popMargTop = ($(registerBox).height() + 24) / 2;
var popMargLeft = ($(registerBox).width() + 24) / 2;
$(registerBox).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
// Add the mask to body
$('body').append('<div id="mask"></div>');
$('#mask').fadeIn(300);
return false;
});
$("#.log-out.button").click(function() {
$.ajax({
url: "components/logout.php",
success: function(data) {
var notification = noty({text: "Successfully logged out!" , type:"success", timeout: 2500, layout:"topCenter"});
setTimeout(function(){
window.location = document.URL;
}, 3000);
},
error: function(html) {
alert('error');
},
statusCode: {
404: function() {
//404 here
}
}
});
return false;
});
});发布于 2013-02-08 10:49:45
使用以下命令:
$("#password").keydown(function(event){
if(event.keyCode == 13) {
$('#loginbtn').click();
};
});然后点击你的按钮:
<button id="loginbtn" type="button">Sign in</button>发布于 2013-02-08 09:53:02
首先,$('#.login.button')不会工作。
$('#loginbutton')和
<button id="loginbutton">Log in</button>将要。
这样做之后,您应该始终将事件绑定到表单提交,因为提交表单的方法不止一种。
$('#theform').on('submit', function(){
// do something useful here
});假设它在表单中,按钮提交它。你可以让它做以前的事情,假设你有一个注册和登录按钮,使用相同的电子邮件和密码字段。
$('#loginbutton').on('click', function(){
// do the unique thing here
// then let the form submit
return true;
}); 或者,如果由于某种原因,此按钮不在表单中
$('#loginbutton').on('click', function(){
// do the unique thing here
// then let the form submit
$('#theform').trigger('submit');
});我想这就是你要问的。
https://stackoverflow.com/questions/14764462
复制相似问题