html前端复选框多类多个复选框提交怎么封装选中的数据,提交到后台呢,我后端是php 前端html编码jsonphp 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.baidu.com/s?wd=jquery%20form.serialize&rsv_spt=1&issp=1&f=3&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_pq=976c86ee000029fa&rsv_t=d2a1l5sZ2kgFjsKQqxMc8dS9Uz7Sno3aqEMLcKh1iIMe3NHqOvgMIBNP8vfhDdKPuoVR&oq=jquery%20form.s&inputT=4729&rsv_sug3=22&rsv_sug4=1549&rsv_sug1=15&rsv_sug2=0&rsp=1 表单序列化好多代码都是调试不通的,让人很无语,谁能给个完整的序列化,$post提交的,无返回。。 <!DOCTYPE html ><html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <meta charset="utf-8" /> <meta name="generator" content="editplus" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <script src="http://www.w3school.com.cn/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("#div1").text($("form").serialize()); }); }); </script> </head> <body><form method="post" action=""> <table width="50%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <fieldset style='padding:5px;clear:left;'> <legend><input type='checkbox' class='checkbox' name='menuModule' value='company,company' id='company_company' onClick='goSelect(this.id)' title="客户管理" >客户管理 </legend> <div><input type='checkbox' class='checkbox' name='menuModule' value='company,base' id='company_base' onClick='goSelect(this.id)' title='客户拜访'>客户拜访</div> <div><input type='checkbox' class='checkbox' name='menuModule' value='company,linkMan' id='company_linkMan' onClick='goSelect(this.id)' title='联系人列表' >联系人列表</div> <div><input type='checkbox' class='checkbox' name='menuModule' value='company,linkTouch' id='company_linkTouch' onClick='goSelect(this.id)' title='联系记录列表' >联系记录列表</div> <div><input type='checkbox' class='checkbox' name='menuModule' value='company,rule' id='company_rule' onClick='goSelect(this.id)' title='客户查重设置 ' >客户查重设置 </div> </fieldset> <fieldset style='padding:5px;clear:left;'> <legend><input type='checkbox' class='checkbox' name='menuModule' value='sys,sys' id='sys_sys' onClick='goSelect(this.id)' title="系统设置 " >系统设置 </legend> <div><input type='checkbox' class='checkbox' name='menuModule' value='sys,group' id='sys_group' onClick='goSelect(this.id)' title='部门设置' >部门设置</div> <div><input type='checkbox' class='checkbox' name='menuModule' value='sys,user' id='sys_user' onClick='goSelect(this.id)' title='人事管理' >人事管理</div> <div><input type='checkbox' class='checkbox' name='menuModule' value='sys,role' id='sys_role' onClick='goSelect(this.id)' title='操作权限组' >操作权限组</div> <div><input type='checkbox' class='checkbox' name='menuModule' value='sys,province' id='sys_province' onClick='goSelect(this.id)' title='省份资料' >省份资料</div> <div><input type='checkbox' class='checkbox' name='menuModule' value='sys,city' id='sys_city' onClick='goSelect(this.id)' title='城市资料' >城市资料</div> <div><input type='checkbox' class='checkbox' name='menuModule' value='sys,code' id='sys_code' onClick='goSelect(this.id)' title='编码规则' >编码规则</div> </fieldset> <fieldset style='padding:5px;clear:left;'> <legend><input type='checkbox' class='checkbox' name='menuModule' value='report,report' id='report_report' onClick='goSelect(this.id)' title="报表与分析" >报表与分析 </legend> <div><input type='checkbox' class='checkbox' name='menuModule' value='report,khflfx' id='report_khflfx' onClick='goSelect(this.id)' title='客户分类分析 ' >客户分类分析 </div> <div><input type='checkbox' class='checkbox' name='menuModule' value='report,khfx' id='report_khfx' onClick='goSelect(this.id)' title='客户分析 ' >客户分析 </div> </fieldset></td> </tr></table></form><button>序列化表单值</button><div id="div1"></div> </body></html>不明白你说的调试不通是啥意思 就是用那些$.ajax,$post老是执行不动,不能提交,界面没反应,这两天在搞,再试试表单序列化,也可能是我代码不对 提交搞定,用序列化表单,后端用,拆解json串,转换数组,最后遍历,插入数据库,但是怎么再从后端数据库中取出,并展现到前端呢? 搞定了,给出一版jquery脚本,有需要的参考下,哈哈 function goSelect(id) { var menuModule = $("#" + id).val(); var array = menuModule.split(","); //获取到的值以","分割 if (array[0] != array[1]) { // 如果操作是子[查找 更新 删除] if ($("#" + id)[0].checked) { // 如果子[查找,更新 删除]中有一个处于选中状态,则客户管理处于选中状态. var superid = array[0] + "_" + array[0]; //组织父id $("#" + superid).prop("checked", "checked"); } else { //flase:表示子子[查找 更新 删除]没有被选中的 //true:表示子[查找 更新 删除]至少有一个被选中的 var flag = false; var $sub = $("input[name=menuModule][value^=" + array[0] + "]:not([value$=" + array[0] + "])"); $sub.each(function(index, domEle) { // 遍历所有的子[查找 更新 删除] if (domEle.checked) { flag = true; } }); if (!flag) { // 如果都没有被选中,则客户管理处于不选中状态. var superid = array[0] + "_" + array[0]; //组织父id $("#" + superid).prop("checked", null); } if (flag) { // 如果至少有一个被选中,则模块处于选中状态. //不管 } } } if (array[0] == array[1]) { // 如果操作的是模块net if ($("#" + id)[0].checked) { // 如果模块处于选中状态,则子[查找 更新 删除]处于选中状态. $("input[name=menuModule][value^=" + array[0] + "]:not([value$=" + array[0] + "])").prop("checked", "checked"); } else { // 如果客户管理处于不选中状态,则子[查找 更新 删除]处于不选中状态. $("input[name=menuModule][value^=" + array[0] + "]:not([value$=" + array[0] + "])").prop("checked", null); } } }序列化$('#btn').bind('click', function() { var serializeObj = {}; //目标对象 var array = $("form").serializeArray(); //转换数组格式 $(array).each(function() { // 遍历数组的每个元素 {name : xx , value : xxx} if (serializeObj[this.name]) { // 判断对象中是否已经存在 name,如果存在name if ($.isArray(serializeObj[this.name])) { serializeObj[this.name].push(this.value); } else { // 将元素变为 数组 serializeObj[this.name] = [serializeObj[this.name], this.value]; } } else { serializeObj[this.name] = this.value; // 如果元素name不存在,添加一个属性 name:value } }); var serializeJSON = JSON.stringify(serializeObj); document.getElementById("hid").value = serializeJSON; form1.action = "/index.php/Home/Mids/AddMarks"; form1.submit(); }); 就是用键盘敲击啊,就有一个超链接能够出现点击的效果,(触发onclick),请问高手该如何写代码? 我的第一个dwr,出错了。 谁能帮我分析google的这一段js代码的?现金奖励RMB200元 100分其实很难赚的(关于iframe) js获得get值问题 问题 让鼠标移动到某个小球上时,他就不断的变换颜色,这段代码,怎么写呢? 一个很棘手的问题,关于WEB中字大小控制的问题,请高手帮忙解决 弱智问题!别嫌弃! 如果判断prompt是按了确定还是取消按钮? jquery mobile框架下CheckBox的问题 请高手帮忙看下 关于 IE兼容 maxlength问题
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta charset="utf-8" />
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script src="http://www.w3school.com.cn/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("#div1").text($("form").serialize());
});
});
</script>
</head> <body>
<form method="post" action="">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<fieldset style='padding:5px;clear:left;'>
<legend><input type='checkbox' class='checkbox' name='menuModule' value='company,company'
id='company_company' onClick='goSelect(this.id)'
title="客户管理" >客户管理
</legend>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='company,base'
id='company_base' onClick='goSelect(this.id)'
title='客户拜访'>客户拜访</div>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='company,linkMan'
id='company_linkMan' onClick='goSelect(this.id)'
title='联系人列表' >联系人列表</div>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='company,linkTouch'
id='company_linkTouch' onClick='goSelect(this.id)'
title='联系记录列表' >联系记录列表</div>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='company,rule'
id='company_rule' onClick='goSelect(this.id)'
title='客户查重设置 ' >客户查重设置 </div>
</fieldset> <fieldset style='padding:5px;clear:left;'>
<legend><input type='checkbox' class='checkbox' name='menuModule' value='sys,sys'
id='sys_sys' onClick='goSelect(this.id)'
title="系统设置 "
>系统设置
</legend>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='sys,group'
id='sys_group' onClick='goSelect(this.id)'
title='部门设置'
>部门设置</div>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='sys,user'
id='sys_user' onClick='goSelect(this.id)'
title='人事管理' >人事管理</div>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='sys,role'
id='sys_role' onClick='goSelect(this.id)'
title='操作权限组' >操作权限组</div>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='sys,province'
id='sys_province' onClick='goSelect(this.id)'
title='省份资料' >省份资料</div>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='sys,city'
id='sys_city' onClick='goSelect(this.id)'
title='城市资料' >城市资料</div>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='sys,code'
id='sys_code' onClick='goSelect(this.id)'
title='编码规则' >编码规则</div> </fieldset> <fieldset style='padding:5px;clear:left;'>
<legend><input type='checkbox' class='checkbox' name='menuModule' value='report,report'
id='report_report' onClick='goSelect(this.id)'
title="报表与分析" >报表与分析
</legend>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='report,khflfx'
id='report_khflfx' onClick='goSelect(this.id)'
title='客户分类分析 ' >客户分类分析 </div>
<div><input type='checkbox' class='checkbox' name='menuModule'
value='report,khfx'
id='report_khfx' onClick='goSelect(this.id)'
title='客户分析 ' >客户分析 </div>
</fieldset>
</td>
</tr>
</table>
</form>
<button>序列化表单值</button>
<div id="div1"></div>
</body>
</html>不明白你说的调试不通是啥意思
var menuModule = $("#" + id).val();
var array = menuModule.split(","); //获取到的值以","分割
if (array[0] != array[1]) { // 如果操作是子[查找 更新 删除]
if ($("#" + id)[0].checked) { // 如果子[查找,更新 删除]中有一个处于选中状态,则客户管理处于选中状态.
var superid = array[0] + "_" + array[0]; //组织父id
$("#" + superid).prop("checked", "checked");
} else {
//flase:表示子子[查找 更新 删除]没有被选中的
//true:表示子[查找 更新 删除]至少有一个被选中的
var flag = false;
var $sub = $("input[name=menuModule][value^=" + array[0] + "]:not([value$=" + array[0] + "])");
$sub.each(function(index, domEle) { // 遍历所有的子[查找 更新 删除]
if (domEle.checked) {
flag = true;
}
});
if (!flag) { // 如果都没有被选中,则客户管理处于不选中状态.
var superid = array[0] + "_" + array[0]; //组织父id
$("#" + superid).prop("checked", null);
}
if (flag) { // 如果至少有一个被选中,则模块处于选中状态.
//不管
}
}
}
if (array[0] == array[1]) { // 如果操作的是模块net
if ($("#" + id)[0].checked) { // 如果模块处于选中状态,则子[查找 更新 删除]处于选中状态.
$("input[name=menuModule][value^=" + array[0] + "]:not([value$=" + array[0] + "])").prop("checked", "checked");
} else { // 如果客户管理处于不选中状态,则子[查找 更新 删除]处于不选中状态.
$("input[name=menuModule][value^=" + array[0] + "]:not([value$=" + array[0] + "])").prop("checked", null);
}
}
}
序列化$('#btn').bind('click', function() {
var serializeObj = {}; //目标对象
var array = $("form").serializeArray(); //转换数组格式
$(array).each(function() { // 遍历数组的每个元素 {name : xx , value : xxx}
if (serializeObj[this.name]) { // 判断对象中是否已经存在 name,如果存在name
if ($.isArray(serializeObj[this.name])) {
serializeObj[this.name].push(this.value);
} else { // 将元素变为 数组
serializeObj[this.name] = [serializeObj[this.name], this.value];
}
} else {
serializeObj[this.name] = this.value; // 如果元素name不存在,添加一个属性 name:value
}
}); var serializeJSON = JSON.stringify(serializeObj);
document.getElementById("hid").value = serializeJSON;
form1.action = "/index.php/Home/Mids/AddMarks";
form1.submit();
});