根据theforever大侠的提示,功能已经实现了。只是实现得比较麻烦,判断很多,通用性还不够好,有小bug。
这个是公司的页面模型
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>test</title>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.js"></script>
<script type="text/javascript"> function chkThese(chkObj) { //多行多列选择
$("[id*="+chkObj.id+"]:checkbox").attr("checked",chkObj.checked);
var n = chkObj.id;
var names = n.split('-'); //取消选择
if(chkObj.checked!=true){
$("[id="+names[0]+"]:Checkbox").removeAttr("checked");
$("[id="+names[1]+"]:Checkbox").removeAttr("checked");
$("[id="+names[1]+"-"+names[2]+"]:Checkbox").removeAttr("checked");
} //判断是否全选,如果全部选择,则全部checkbox都选择
var isChk=true;
var oL=document.getElementsByName(chkObj.name);
if(oL!=null){
if(oL.length>0){
for(var i=0;i<oL.length;i++){
if(oL[i].checked==false){
isChk=false;
break;
}
}
}
}
if(isChk==true) {
$("[id="+names[0]+"]:Checkbox").attr("checked",true);
$("[id="+names[1]+"]:Checkbox").attr("checked",true);
$("[id*=]:Checkbox").attr("checked",true);
} //行选择
var arr = $("[id*="+names[0]+"]:Checkbox");
var fChk = true;
for(var i=1;i<arr.length;i++) {
if(arr[i].checked==false) {
fChk = false;
break;
}
}
if(fChk==true) {
arr = $("[id*="+names[0]+"]:Checkbox").attr("checked",true);
} //列选择
var arrs = $("[id*="+names[2]+"]:Checkbox");
var cChek = true;
for(var i=1;i<arrs.length;i++) {
if(arrs[i].checked==false) {
cChek = false;
break;
}
}
var cxsCheck = true;
if(cChek==true) {
$("[id*="+names[2]+"]:Checkbox").attr("checked",true);
} //多列选择
var cxs = $("[id*="+names[1]+"]:Checkbox");
for(var i=1;i<cxs.length;i++) {
if(cxs[i].checked==false) {
cxsCheck = false;
break;
}
}
if(cxsCheck==true) {
$("[id*="+names[1]+"]:Checkbox").attr("checked",true);
} //取消行选
var dys = $("[name*='dy']:Checkbox");
for(var i=0;i<dys.length;i++) {
$(dys[i]).bind("click", function(){
for(var j=0;j<dys.length;j++) {
if(dys[j].checked==false) {
$("[name='lc']:Checkbox").removeAttr("checked");
}
}
}
);
} //取消列选
var lcs = $("[name='lc']:Checkbox");
for(var i=0;i<lcs.length;i++) {
$(lcs[i]).bind("click",function() {
for(var j=0;j<lcs.length;j++) {
if(lcs[j].checked==false) {
$("[name*='dy']:Checkbox").removeAttr("checked");
}
}
});
}
}</script>
<style>
li {list-style:none;}
td {text-align:center;}
</style>
</head>
<body>
<center >
<table border="1" id="tab">
<tr>
<td width="69" height="113" rowspan="2">楼层</td>
<td height="55" colspan="4">
<input type="checkbox" id="A-" name="dy" value="checkbox" onclick="chkThese(this)">A
</td>
<td colspan="4">
<input type="checkbox" id="B-" name="dy" value="checkbox" onclick="chkThese(this)">B
</td>
</tr>
<tr>
<td height="28" colspan="2">
<input type="checkbox" id="A-A1" name="dy-cx" value="checkbox" onclick="chkThese(this)">1
</td>
<td height="28" colspan="2">
<input type="checkbox" id="A-A2" name="dy-cx" value="checkbox" onclick="chkThese(this)">2
</td>
<td colspan="2">
<input type="checkbox" id="B-B1" name="dy-cx" value="checkbox" onclick="chkThese(this)">1
</td>
<td colspan="2">
<input type="checkbox" id="B-B2" name="dy-cx" value="checkbox" onclick="chkThese(this)">2
</td>
</tr>
<tr>
<td height="107">
<input type="checkbox" id="3F" name="lc" value="checkbox" onclick="chkThese(this)">3F
</td>
<td width="70">
<div class='cell-layout'>
<ul class="left-over"><li></li></ul>
</div>
<div class='detail'></div>
<div class='detail'>
<input type="checkbox" id="3F-A-A1" name="house" value="checkbox" onclick="chkThese(this)">3A-1
</div>
</td>
<td width="75">
<P>
<div class='cell-layout'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</div>
</td>
<td width="53">
<div class='cell-layout'>
<ul class='left'><li></li></ul>
</div>
<div class='detail'></div>
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="3F-A-A2" name="house" value="checkbox" onclick="chkThese(this)"> 3A-2</span>
</div>
</td>
<td width="92">
<P>
<div class='cell-layout'>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</div>
</td>
<td width="53">
<div class='cell-layout'>
<ul class='left'><li></li></ul>
</div>
<div class='detail'></div>
<div class='cell-layout'>
<div class='cell-layout'>
<ul class='left'><li></li></ul>
</div>
<div class='detail'></div>
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="3F-B-B1" name="house" value="checkbox" onclick="chkThese(this)"> 3B-1</span>
</div>
</div>
</td>
<td width="86">
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</td>
<td width="59">
<div class='cell-layout'>
<div class='cell-layout'>
<div class='detail'></div>
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="3F-B-B2" name="house" value="checkbox" onclick="chkThese(this)"> 3B-2</span>
</div>
</div>
</div>
</td>
<td width="112">
<P>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</td>
</tr>
<tr>
<td width="69" height="107">
<input type="checkbox" id="2F" name="lc" value="checkbox" onclick="chkThese(this,'2F')">2F
</td>
<td width="70">
<div class='cell-layout'>
<ul class="left-over"><li></li></ul>
</div>
<div class='detail'></div>
<input type="checkbox" id="2F-A-A1" name="house" value="checkbox" onclick="chkThese(this)">2A-1
</div>
</td>
<td width="75">
<P>
<ul class="left-over"><li></li></ul>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</td>
<td width="53">
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="2F-A-A2" name="house" value="checkbox" onclick="chkThese(this)"> 2A-2</span>
</div>
</td>
<td width="92">
<P>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</td>
<td width="53">
<div class='cell-layout'>
<ul class='left'><li></li></ul>
</div>
<div class='cell-layout'>
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="2F-B-B1" name="house" value="checkbox" onclick="chkThese(this)"> 2B-1</span>
</div>
</div>
</td>
<td width="86">
<P>
<ul class='left'><li></li></ul>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</td>
<td width="59">
<div class='cell-layout'>
<ul class='left'><li></li></ul>
</div>
<div class='cell-layout'>
<div class='cell-layout'>
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="2F-B-B2" name="house" value="checkbox" onclick="chkThese(this)"> 2B-2</span>
</div>
</div>
</div>
</td>
<td width="112">
<P>
<ul class='left'><li></li></ul>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</td>
</tr>
</table>
</center>
</body>
</html>
这个是公司的页面模型
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>test</title>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.js"></script>
<script type="text/javascript"> function chkThese(chkObj) { //多行多列选择
$("[id*="+chkObj.id+"]:checkbox").attr("checked",chkObj.checked);
var n = chkObj.id;
var names = n.split('-'); //取消选择
if(chkObj.checked!=true){
$("[id="+names[0]+"]:Checkbox").removeAttr("checked");
$("[id="+names[1]+"]:Checkbox").removeAttr("checked");
$("[id="+names[1]+"-"+names[2]+"]:Checkbox").removeAttr("checked");
} //判断是否全选,如果全部选择,则全部checkbox都选择
var isChk=true;
var oL=document.getElementsByName(chkObj.name);
if(oL!=null){
if(oL.length>0){
for(var i=0;i<oL.length;i++){
if(oL[i].checked==false){
isChk=false;
break;
}
}
}
}
if(isChk==true) {
$("[id="+names[0]+"]:Checkbox").attr("checked",true);
$("[id="+names[1]+"]:Checkbox").attr("checked",true);
$("[id*=]:Checkbox").attr("checked",true);
} //行选择
var arr = $("[id*="+names[0]+"]:Checkbox");
var fChk = true;
for(var i=1;i<arr.length;i++) {
if(arr[i].checked==false) {
fChk = false;
break;
}
}
if(fChk==true) {
arr = $("[id*="+names[0]+"]:Checkbox").attr("checked",true);
} //列选择
var arrs = $("[id*="+names[2]+"]:Checkbox");
var cChek = true;
for(var i=1;i<arrs.length;i++) {
if(arrs[i].checked==false) {
cChek = false;
break;
}
}
var cxsCheck = true;
if(cChek==true) {
$("[id*="+names[2]+"]:Checkbox").attr("checked",true);
} //多列选择
var cxs = $("[id*="+names[1]+"]:Checkbox");
for(var i=1;i<cxs.length;i++) {
if(cxs[i].checked==false) {
cxsCheck = false;
break;
}
}
if(cxsCheck==true) {
$("[id*="+names[1]+"]:Checkbox").attr("checked",true);
} //取消行选
var dys = $("[name*='dy']:Checkbox");
for(var i=0;i<dys.length;i++) {
$(dys[i]).bind("click", function(){
for(var j=0;j<dys.length;j++) {
if(dys[j].checked==false) {
$("[name='lc']:Checkbox").removeAttr("checked");
}
}
}
);
} //取消列选
var lcs = $("[name='lc']:Checkbox");
for(var i=0;i<lcs.length;i++) {
$(lcs[i]).bind("click",function() {
for(var j=0;j<lcs.length;j++) {
if(lcs[j].checked==false) {
$("[name*='dy']:Checkbox").removeAttr("checked");
}
}
});
}
}</script>
<style>
li {list-style:none;}
td {text-align:center;}
</style>
</head>
<body>
<center >
<table border="1" id="tab">
<tr>
<td width="69" height="113" rowspan="2">楼层</td>
<td height="55" colspan="4">
<input type="checkbox" id="A-" name="dy" value="checkbox" onclick="chkThese(this)">A
</td>
<td colspan="4">
<input type="checkbox" id="B-" name="dy" value="checkbox" onclick="chkThese(this)">B
</td>
</tr>
<tr>
<td height="28" colspan="2">
<input type="checkbox" id="A-A1" name="dy-cx" value="checkbox" onclick="chkThese(this)">1
</td>
<td height="28" colspan="2">
<input type="checkbox" id="A-A2" name="dy-cx" value="checkbox" onclick="chkThese(this)">2
</td>
<td colspan="2">
<input type="checkbox" id="B-B1" name="dy-cx" value="checkbox" onclick="chkThese(this)">1
</td>
<td colspan="2">
<input type="checkbox" id="B-B2" name="dy-cx" value="checkbox" onclick="chkThese(this)">2
</td>
</tr>
<tr>
<td height="107">
<input type="checkbox" id="3F" name="lc" value="checkbox" onclick="chkThese(this)">3F
</td>
<td width="70">
<div class='cell-layout'>
<ul class="left-over"><li></li></ul>
</div>
<div class='detail'></div>
<div class='detail'>
<input type="checkbox" id="3F-A-A1" name="house" value="checkbox" onclick="chkThese(this)">3A-1
</div>
</td>
<td width="75">
<P>
<div class='cell-layout'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</div>
</td>
<td width="53">
<div class='cell-layout'>
<ul class='left'><li></li></ul>
</div>
<div class='detail'></div>
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="3F-A-A2" name="house" value="checkbox" onclick="chkThese(this)"> 3A-2</span>
</div>
</td>
<td width="92">
<P>
<div class='cell-layout'>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</div>
</td>
<td width="53">
<div class='cell-layout'>
<ul class='left'><li></li></ul>
</div>
<div class='detail'></div>
<div class='cell-layout'>
<div class='cell-layout'>
<ul class='left'><li></li></ul>
</div>
<div class='detail'></div>
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="3F-B-B1" name="house" value="checkbox" onclick="chkThese(this)"> 3B-1</span>
</div>
</div>
</td>
<td width="86">
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</td>
<td width="59">
<div class='cell-layout'>
<div class='cell-layout'>
<div class='detail'></div>
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="3F-B-B2" name="house" value="checkbox" onclick="chkThese(this)"> 3B-2</span>
</div>
</div>
</div>
</td>
<td width="112">
<P>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</td>
</tr>
<tr>
<td width="69" height="107">
<input type="checkbox" id="2F" name="lc" value="checkbox" onclick="chkThese(this,'2F')">2F
</td>
<td width="70">
<div class='cell-layout'>
<ul class="left-over"><li></li></ul>
</div>
<div class='detail'></div>
<input type="checkbox" id="2F-A-A1" name="house" value="checkbox" onclick="chkThese(this)">2A-1
</div>
</td>
<td width="75">
<P>
<ul class="left-over"><li></li></ul>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</td>
<td width="53">
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="2F-A-A2" name="house" value="checkbox" onclick="chkThese(this)"> 2A-2</span>
</div>
</td>
<td width="92">
<P>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</td>
<td width="53">
<div class='cell-layout'>
<ul class='left'><li></li></ul>
</div>
<div class='cell-layout'>
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="2F-B-B1" name="house" value="checkbox" onclick="chkThese(this)"> 2B-1</span>
</div>
</div>
</td>
<td width="86">
<P>
<ul class='left'><li></li></ul>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</td>
<td width="59">
<div class='cell-layout'>
<ul class='left'><li></li></ul>
</div>
<div class='cell-layout'>
<div class='cell-layout'>
<div class='cell-layout'>
<span class="detail"> <input type="checkbox" id="2F-B-B2" name="house" value="checkbox" onclick="chkThese(this)"> 2B-2</span>
</div>
</div>
</div>
</td>
<td width="112">
<P>
<ul class='left'><li></li></ul>
<ul class='right'>
<li>122.00m2</li>
<li>两房一厅</li>
<li>园林/东南</li>
<li>A套餐</li>
</ul>
</td>
</tr>
</table>
</center>
</body>
</html>
解决方案 »
- 一个由图片组成的页面,jQuery无法获得页面正确文档高度
- getAttributeNode("style").nodeValue 为什么得不到值,明白后立即结分
- js中遇到的特殊语法(&& || !! 的使用方式),请高手指点
- 一句话:祝大家在新的一年里万事如意!!!
- js销毁/隐藏网页对象(div)问题
- 关于浏览器插件的检测
- 没人会吗???急死了!!!在线等!!!
- ··········怎么生成1到4之前的随机数呀。解决马上给分
- 请问怎样使打开首页时页面可以像window.open一样?
- showModalDialog()、showModelessDialog()方法时参数传递的问题
- jquery ui datepicker显示的日期选择框被select档住了
- 很急 求 JS 幻灯 相似的也行
先选中A A下面的都被选中了
这时候 取消任意一项 1或者2对应的都会被取消
但是A不会
A应该也要取消勾选
够细心。将A和B的checkbox里的ID改为"A" "B"就好了,去掉“-”。
其实还有bug,但是确实想不出来怎么做了
选择一行2F或者3F(不能同时选)时,再选择1或2,2F的checkbox就取消选择了。理论上应该保留2F的checkbox选择
楼主自己添加的JS,大概看了一下,如果用JQ的方法去写,可以简化不少的。
楼主上面说还有BUG,最好把问题说得清楚些,我帮你再看看。因为我不喜欢没有针对性的去看代码。
我试了很多用JQ方法去写,对JQ很多一些方法还是不懂,只能用笨方法了。
至于那个bug,
选择一行2F或者3F(不能同时选)时,再选择1或2,2F的checkbox就取消选择了。理论上应该保留2F的checkbox选择
这个是比较明显的,其他暂时没有发现。
我觉得公司这个页面的设计就不太好,太难用了,一个页面做太多功能了
提点建议:
1,如果能有"部分选择"的提醒,则更好!
2,如果给个提交钮,显示一下选择,则可以更好的验证.
3,取掉charset=utf-8的那行(出现乱码,老是要调整)