欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery按回車提交數(shù)據(jù)的代碼示例

 更新時間:2013年11月05日 16:01:37   作者:  
jquery按回車提交數(shù)據(jù)的代碼示例,很簡單的一個方法,看一下就明白
其實(shí)jquery按回車提交數(shù)據(jù)是很簡單的事情,我們只要檢查測到用戶按了回車就直接綁定事件.click就實(shí)現(xiàn)了提交了,在按鈕上我們綁定ajax提交表單事件即可。
核心代碼
 
復(fù)制代碼 代碼如下:

$(document).ready(function(){
$("按下回車的控件").keydown(function(e){
var curKey = e.which;
if(curKey == 13){
$("#回車事件按鈕控件").click();
return false;
}
});
});
 

是用js的ajax功能同時支持回車事件
復(fù)制代碼 代碼如下:

document.onkeydown = function (e) {
var theEvent = window.event || e;
var code = theEvent.keyCode || theEvent.which;
if (code == 13) {
$("#login_submit").click();
}


$(document).ready(function() {
    //登錄提交
    $("#login_submit").bind('click',function(){
        var username=$("#username").val();
        var password=$("#password").val();

        $.ajax({
                type : 'POST',
                url : './login.php',
                data: {type :'ajax',username:username,password:password},
                success : function(msg){
                    //alert(msg);
                    if(msg==-1){
                        alert('用戶名不能為空');
                        $("#username").focus();
                    }
                    if(msg==-2){
                        alert('用戶名不存在');
                        $("#username").val("");
                        $("#username").focus();
                    }
                    if(msg==-3){
                        alert('密碼不能為空');
                        $("#password").focus();
                    }
                    if(msg==-6){
                        alert('密碼輸入不正確');
                        $("#password").focus();
                    }
                    if(msg==1){
                        //alert('登錄成功');
                        window.location.href='./index.php';
                    }

                }
            });
    });

});
 

相關(guān)文章

最新評論