jquery按回車提交數(shù)據(jù)的代碼示例
更新時間:2013年11月05日 16:01:37 作者:
jquery按回車提交數(shù)據(jù)的代碼示例,很簡單的一個方法,看一下就明白
其實jquery按回車提交數(shù)據(jù)是很簡單的事情,我們只要檢查測到用戶按了回車就直接綁定事件.click就實現(xiàn)了提交了,在按鈕上我們綁定ajax提交表單事件即可。
核心代碼
$(document).ready(function(){
$("按下回車的控件").keydown(function(e){
var curKey = e.which;
if(curKey == 13){
$("#回車事件按鈕控件").click();
return false;
}
});
});
是用js的ajax功能同時支持回車事件
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';
}
}
});
});
});
核心代碼
復制代碼 代碼如下:
$(document).ready(function(){
$("按下回車的控件").keydown(function(e){
var curKey = e.which;
if(curKey == 13){
$("#回車事件按鈕控件").click();
return false;
}
});
});
是用js的ajax功能同時支持回車事件
復制代碼 代碼如下:
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';
}
}
});
});
});
相關文章
jQuery實現(xiàn)仿淘寶帶有指示條的圖片轉動切換效果完整實例
這篇文章主要介紹了jQuery實現(xiàn)仿淘寶帶有指示條的圖片轉動切換效果的方法,以完整實例形式較為詳細的分析了jQuery圖片特效的使用技巧,需要的朋友可以參考下2015-03-03jquery 重寫 ajax提交并判斷權限后 使用load方法報錯解決方法
這篇文章主要介紹了jquery 重寫 ajax提交并判斷權限后 使用load方法報錯解決方法 的相關資料,需要的朋友可以參考下2016-01-01jQuery+CSS實現(xiàn)菜單滑動伸展收縮(仿淘寶)
淘寶網(wǎng)上的菜單滑動伸展收縮想必大家不會很陌生吧,接下來本文也使用jquery+css實現(xiàn)一個,代碼很簡潔功能很使用,感興趣的各位可以不要錯過了哈2013-03-03jquery數(shù)組封裝使用方法分享(jquery數(shù)組遍歷)
JQuery對數(shù)組的處理非常便捷并且功能強大齊全,一步到位的封裝了很多原生js數(shù)組不能企及的功能。下面來看看JQuery數(shù)組的強大之處在哪。2014-03-03jQuery實現(xiàn)簡易的輸入框字數(shù)計數(shù)功能示例
這篇文章主要介紹了jQuery實現(xiàn)簡易的輸入框字數(shù)計數(shù)功能,結合實例形式分析了jQuery針對頁面元素屬性的獲取與計算相關操作技巧,需要的朋友可以參考下2017-01-01jQuery插件Flexslider實現(xiàn)圖片輪播、圖文結合滑動切換效果
這篇文章主要介紹了jQuery插件Flexslider實現(xiàn)圖片輪播、圖文結合滑動切換效果的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-07-07