---
title: "一个星期中某一天存在即显示的思路"
author: "uule"
date: "2011-05-31T17:48:59Z"
tags: ["F#"]
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-05-31T14:46:43Z"
id: 1066519
url: "https://uule.iteye.com/blog/1066519"
---

1、  
![](http://dl.iteye.com/upload/attachment/491036/ddea7774-8eaa-3903-90d2-bdc70026b5ed.png)

days:  1,2,3,4,5,6,0     //数据库中的每条数据对应一条记录  
        或1,2,3,4,0  
        或5,6  
         ...

 

```
rateRecord[rateRecord.length] = (isDayExist(days, 1)==true) ? '<td style="color:#4a6129; width:20px; text-align:center;">M</td>' : '<td style="font-weight:bold;font-size:14px;">&nbsp; </td>';
rateRecord[rateRecord.length] = (isDayExist(days, 2)==true) ? '<td style="">T</td>' : '<td style="">&nbsp; </td>';
rateRecord[rateRecord.length] = (isDayExist(days, 3)==true) ? '<td style="">W</td>' : '<td style="">&nbsp; </td>';
rateRecord[rateRecord.length] = (isDayExist(days, 4)==true) ? '<td style="">T</td>' : '<td style="">&nbsp; </td>';
rateRecord[rateRecord.length] = (isDayExist(days, 5)==true) ? '<td style="">F</td>' : '<td style="">&nbsp; </td>';
rateRecord[rateRecord.length] = (isDayExist(days, 6)==true) ? '<td style="">S</td>' : '<td style="">&nbsp; </td>';
rateRecord[rateRecord.length] = (isDayExist(days, 0)==true) ? '<td style="">S</td>' : '<td style="">&nbsp; </td>';
```

 

```
//如果该条记录某天存在
function isDayExist(days, dayNo) {
		for (var i=0; i<days.length; i++) {
			if (days[i] == dayNo) return true;
		}
		return false;
	}
```

 

 

2、

![](http://dl.iteye.com/upload/attachment/0068/9131/6edd2b6c-2810-3ad7-b39a-4f841cc3137e.png)

 

```
<td>
<table style="margin:auto; width:40%;text-align:left;" cellpadding="0" cellspacing="0" >
	<tr>
		<td style="text-align:center;">All</td>
		<td style="text-align:center;">Mon</td>
		<td style="text-align:center;">Tue</td>
		<td style="text-align:center;">Wed</td>
		<td style="text-align:center;">Thu</td>
		<td style="text-align:center;">Fri</td>
		<td style="text-align:center;">Sat</td>
		<td style="text-align:center;">Sun</td>
	</tr>
	<tr>
		<td style="text-align:center;"><input id="idAllWeek" name="idAllWeek" type="checkbox" onclick='checkAllWeekStatus(this);' /></td>
		<td style="text-align:center;"><input id="mon" name="mon" type="checkbox" /></td>
		<td style="text-align:center;"><input id="tue" name="tue" type="checkbox" /></td>
		<td style="text-align:center;"><input id="wed" name="wed" type="checkbox" /></td>
		<td style="text-align:center;"><input id="thu" name="thu" type="checkbox" /></td>
		<td style="text-align:center;"><input id="fri" name="fri" type="checkbox" /></td>
		<td style="text-align:center;"><input id="sat" name="sat" type="checkbox" /></td>
		<td style="text-align:center;"><input id="sun" name="sun" type="checkbox" /></td>
	</tr>
</table>
</td>
```

 

```
function saveOrUpdateWeek(){
			var daysStr = "";
			var days = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
			for (var i=0; i<days.length; i++) {
				if (jQuery("#"+days[i]).attr("checked") == true) {
				   daysStr += i+",";
				}
			}
			daysStr = daysStr.substring(0,daysStr.length-1);
			jQuery("#dayOfWeek").val(daysStr);
		}
		
		function initDayOfWeek(str){
			jQuery("input[type='checkbox']").attr("checked",false);
			var days = str.split(",");
			if(days.length == 7) {
				jQuery("#idAllWeek").attr("checked",true);
			}else{
				jQuery("#idAllWeek").attr("checked",false);
			}
			for(var i =0;i<days.length;i++){
				switch (days[i]) {
					case '0': jQuery('#sun').attr("checked",true); break;
					case '1': jQuery('#mon').attr("checked",true); break;
					case '2': jQuery('#tue').attr("checked",true); break;
					case '3': jQuery('#wed').attr("checked",true); break;
					case '4': jQuery('#thu').attr("checked",true); break;
					case '5': jQuery('#fri').attr("checked",true); break;
					case '6': jQuery('#sat').attr("checked",true); break;
				}
			}
		}
		
		function checkAllWeekStatus( chkObj ) {
			if ( chkObj.checked ) { 
				jQuery('#mon').attr("checked",true);
				jQuery('#tue').attr("checked",true);
				jQuery('#wed').attr("checked",true);
				jQuery('#thu').attr("checked",true);
				jQuery('#fri').attr("checked",true);
				jQuery('#sat').attr("checked",true);
				jQuery('#sun').attr("checked",true);
			} else {
				jQuery('#mon').attr("checked",false);
				jQuery('#tue').attr("checked",false);
				jQuery('#wed').attr("checked",false);
				jQuery('#thu').attr("checked",false);
				jQuery('#fri').attr("checked",false);
				jQuery('#sat').attr("checked",false);
				jQuery('#sun').attr("checked",false);
			}
		}
```

 

。。。。。。。