$('#.login.button').click(function() {
と
$('#.register.button').click(function() {
これらは両方とも機能しますが、クリックまたはEnterキーでスクリプトを実行するにはどうすればよいですか?
これが私の.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;
});
});