<script type="text/javascript">
$(function() {
$("#Btn").click(function() {
var params = $("#myform").serializeObject(); //将表单序列化为JSON对象
console.info(params);
})
})
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [ o[this.name] ];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
}
</script>
批量判断表单input是否为空
<script type="text/javascript">
function check() {
var res=false;
$(".weui-input").each(function(){
if($(this).val() == ''){
$.toast("不能为空", "cancel");
$(this).focus();
res=false;
return false;
}
res=true;
})
return res;
}
$(".sub").click(function(){
if(check()!=false){
....
}
}
</script>