When working on a project, I encountered the situation where the "enter" key was bound, and I directly intercepted the situation code. The code is as follows:
The code copy is as follows:
function sendLoginData(){
loginvalidateForm();
$(document).keydown(function(event){
if(event.keyCode == 13){ //Bind Enter
$('#login-submit').click(); /auto/trigger login button
}
});
$('#login-submit').click(function(){
if($('#login-form').valid()==false){
return false;
}
var username = $('#id_username').val();
var password = $('#id_password').val();
$.ajax({
type:"post",
dataType:"json",
contentType:"application/x-www-form-urlencoded;charset=UTF-8",
url:"{% url netPan.User.views.LoginHd%}",
data:{
username: username,
password: password
},
beforeSend: function(){
// Prompt information to improve user experience
$('#loginInfoWord').show().text('Processing, please wait...');
},
success:function(data){
var message = data.message;
if(message == 'D'){
// Prompt information to improve user experience
$('#loginInfoWord').show().text('Login successfully, jumping...');
window.location.href = '{% url netPan.index.IndexHd%}';
}else if(message == 'C'){
$('#loginInfoWord').show().text('Username or password is incorrect');
}else if(message == 'N'){
$('#loginInfoWord').show().text('You are not registered yet!');
}else if(message == 'H'){
$('#loginInfoWord').show().text('You have not activated your account yet, log in to your email to activate your account!');
}
},
error: function(xhr,textStatus,ErrorThrown){
$('#loginInfoWord').show().text('Exception occurred:'+errorThrown);
}
});
});
/* It's OK to put it on the top and bottom, it has nothing to do with the order
$(document).keydown(function(event){
if(event.keyCode == 13){ //Bind Enter
$('#login-submit').click(); /auto/trigger login button
}
});
*/
}