我想在用户点击Enter或提交按钮时提交表单ajax这是我的代码:
$('.setter').on('submit keypress', function(){
$.post(action,$(this).serialize(), function(data){
window[data.jsFunction](data); // or get it form CI as an array data
}, "json");
});
提前致谢
答案 0 :(得分:0)
你试试:
html代码:
<button type="button" id="btnSubmit" onclick="postData()">Submit</button>
javascript代码:
function postData(){
$.post(action,$(this).serialize(), function(data){
window[data.jsFunction](data); // or get it form CI as an array data
}, "json");
}
$(document).keypress(function(e) {
if(e.which == 13) {
postData();
}
});