台灣最大程式設計社群網站
線上人數
608
 
會員總數:246038
討論主題:189625
歡迎您免費加入會員
討論區列表 >> 專欄文章 >> 月曆的checkbox
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
月曆的checkbox
價值 : 0 QP  點閱數:525 回應數:0
樓主

站務人員 站長
門外漢
0 1580
542 9
發送站內信

捐贈 VP 給 站務人員
我現在要做一個月曆

日期我都放了chekbox

我想要在每個星期的上面放選取該星期的所有checkbox

也就是說(以2002年8月為例):

我勾選星期一,則5.12.19.26這四個日期都會呈勾選狀態(checked)

我該怎麼做呢?



-------------------------------------------------------------------------

回應者: 路人甲



<html>

<head>

<title>無標題文件</title>

<meta http-equiv="Content-Type" content="text/html; charset=big5">

</head>

<%



%>

<body bgcolor="#FFFFFF" text="#000000">

<div align="center">

<form name="form1" method="post" action="">

<table border="1" cellspacing="0" cellpadding="1">

<tr>

<td width="80"><input type="checkbox" name="cSun" value="0" onClick="chkSun();"><font color="#FF0000">星期日</font></td>

<td width="80"><input type="checkbox" name="cMon" value="0" onClick="chkMon();">星期一</td>

<td width="80"><input type="checkbox" name="cTue" value="0" onClick="chkTue();">星期二</td>

<td width="80"><input type="checkbox" name="cWed" value="0" onClick="chkWed();">星期三</td>

<td width="80"><input type="checkbox" name="cThu" value="0" onClick="chkThu();">星期四</td>

<td width="80"><input type="checkbox" name="cFri" value="0" onClick="chkFri();">星期五</td>

<td width="80"><input type="checkbox" name="cSat" value="0" onClick="chkSat();"><font color="#009900">星期六</font></td>

</tr>

<%

' 以2002年8月為例

w=DatePart("w","2002/7/1") ' 每月的第一天

Days=31 ' 每月共有多少天



j=(Days-(7-w+1))\7 +1

if (Days-(7-w+1)) mod 7 > 0 then j=j+1

for i=0 to j-1

%>

<tr>

<td width="80"><% if (7*i-w+2) > 0 and (7*i-w+2) <= Days then response.write "<input type='checkbox' name='cSun' value='" & (7*i-w+2) & "'><font color='#FF0000'>" & (7*i-w+2) & "</font>" %> </td>

<td width="80"><% if (7*i-w+2)+1 > 0 and (7*i-w+2)+1 <= Days then response.write "<input type='checkbox' name='cMon' value='" & (7*i-w+2)+1 & "'>" & (7*i-w+2)+1 %> </td>

<td width="80"><% if (7*i-w+2)+2 > 0 and (7*i-w+2)+2 <= Days then response.write "<input type='checkbox' name='cTue' value='" & (7*i-w+2)+2 & "'>" & (7*i-w+2)+2 %> </td>

<td width="80"><% if (7*i-w+2)+3 > 0 and (7*i-w+2)+3 <= Days then response.write "<input type='checkbox' name='cWed' value='" & (7*i-w+2)+3 & "'>" & (7*i-w+2)+3 %> </td>

<td width="80"><% if (7*i-w+2)+4 > 0 and (7*i-w+2)+4 <= Days then response.write "<input type='checkbox' name='cThu' value='" & (7*i-w+2)+4 & "'>" & (7*i-w+2)+4 %> </td>

<td width="80"><% if (7*i-w+2)+5 > 0 and (7*i-w+2)+5 <= Days then response.write "<input type='checkbox' name='cFri' value='" & (7*i-w+2)+5 & "'>" & (7*i-w+2)+5 %> </td>

<td width="80"><% if (7*i-w+2)+6 > 0 and (7*i-w+2)+6 <= Days then response.write "<input type='checkbox' name='cSat' value='" & (7*i-w+2)+6 & "'><font color='#009900'>" & (7*i-w+2)+6 & "</font>" %> </td>

</tr>

<% next %>

</table>

</form>

</div>

</body>

<script Language="Javascript">

function chkSun(){

if (form1.cSun[0].checked) {

for (i=1;i<form1.cSun.length +1;i++)

form1.cSun[i].checked=true;

}

else {

for (i=1;i<form1.cSun.length +1;i++)

form1.cSun[i].checked=false;

}

}

function chkMon(){

if (form1.cMon[0].checked) {

for (i=1;i<form1.cMon.length +1;i++)

form1.cMon[i].checked=true;

}

else {

for (i=1;i<form1.cMon.length +1;i++)

form1.cMon[i].checked=false;

}

}

function chkTue(){

if (form1.cTue[0].checked) {

for (i=1;i<form1.cTue.length +1;i++)

form1.cTue[i].checked=true;

}

else {

for (i=1;i<form1.cTue.length +1;i++)

form1.cTue[i].checked=false;

}

}

function chkWed(){

if (form1.cWed[0].checked) {

for (i=1;i<form1.cWed.length +1;i++)

form1.cWed[i].checked=true;

}

else {

for (i=1;i<form1.cWed.length +1;i++)

form1.cWed[i].checked=false;

}

}

function chkThu(){

if (form1.cThu[0].checked) {

for (i=1;i<form1.cThu.length +1;i++)

form1.cThu[i].checked=true;

}

else {

for (i=1;i<form1.cThu.length +1;i++)

form1.cThu[i].checked=false;

}

}

function chkFri(){

if (form1.cFri[0].checked) {

for (i=1;i<form1.cFri.length +1;i++)

form1.cFri[i].checked=true;

}

else {

for (i=1;i<form1.cFri.length +1;i++)

form1.cFri[i].checked=false;

}

}

function chkSat(){

if (form1.cSat[0].checked) {

for (i=1;i<form1.cSat.length +1;i++)

form1.cSat[i].checked=true;

}

else {

for (i=1;i<form1.cSat.length +1;i++)

form1.cSat[i].checked=false;

}

}

</script>

</html>



-----------------------------------------------------------------

w=DatePart("w","2002/7/1") ' 每月的第一天

Days=31 ' 每月共有多少天



改這兩行 , 月曆排列方式跟著變喔

------------------------------------------------------------------

把script裡面每一個類似for (i=1;i<form1.cThu.length +1;i++)

改成for (i=1;i<form1.cThu.length;i++)

不用 +1



=============================================================================

回應者: 小 luchingyi@mail2000.com.tw



謝謝!謝謝! ^__________^

我將路人甲的例子研究了一個早上

終於懂了,也改成我的寫法,好讓其它有相同問題的可以參考



以下是我的寫法



<html>

<head>

<title>無標題文件</title>

<meta http-equiv="Content-Type" content="text/html; charset=big5">

</head>

<%

' 以2002年9月為例

w=DatePart("w","2002/9/1") ' 每月的第一天



' 抓日期1-7在該星期??

i=1

dim weekd(8)

m=w-1

if m=0 then m=7

for i=1 to 7

weekd(m)=i

m=m+1

if m=8 then m=1

next



Days=31 ' 每月共有多少天

%>

<body bgcolor="#FFFFFF" text="#000000">

<div align="center">

<form name="form1" method="post" action="">

<table border="1" cellspacing="0" cellpadding="1">

<tr><td colspan=7 align=center>9月份 <input type=checkbox name=allday value=0 onClick="chk_all(<%=days%>)">選擇全部的日期</td></tr>

<tr>

<td width="80" align=center><input type="checkbox" name="week_day" value="0" onClick="chk_week_day(7,<%=weekd(7)%>,<%=days%>);">
<font color="#FF0000">星期日</font></td>

<td width="80" align=center><input type="checkbox" name="week_day" value="0" onClick="chk_week_day(1,<%=weekd(1)%>,<%=days%>);">
星期一</td>

<td width="80" align=center><input type="checkbox" name="week_day" value="0" onClick="chk_week_day(2,<%=weekd(2)%>,<%=days%>);">
星期二</td>

<td width="80" align=center><input type="checkbox" name="week_day" value="0" onClick="chk_week_day(3,<%=weekd(3)%>,<%=days%>);">
星期三</td>

<td width="80" align=center><input type="checkbox" name="week_day" value="0" onClick="chk_week_day(4,<%=weekd(4)%>,<%=days%>);">
星期四</td>

<td width="80" align=center><input type="checkbox" name="week_day" value="0" onClick="chk_week_day(5,<%=weekd(5)%>,<%=days%>);">
星期五</td>

<td width="80" align=center><input type="checkbox" name="week_day" value="0" onClick="chk_week_day(6,<%=weekd(6)%>,<%=days%>);">
<font color="#009900">星期六</font></td>

</tr>

<%

'chk_week_day(星期,開始日期,總天數)

j=(Days-(7-w+1))\7 +1

if (Days-(7-w+1)) mod 7 > 0 then j=j+1

for i=0 to j-1

%>

<tr>

<td width="80" align=center><% if (7*i-w+2) > 0 and (7*i-w+2) <= Days then response.write "<input type='checkbox' name='checkday' value='" & (7*i-w+2) & "'>
<font color='#FF0000'>" & (7*i-w+2) & "</font>" else response.write "-"%> </td>

<td width="80" align=center><% if (7*i-w+2)+1 > 0 and (7*i-w+2)+1 <= Days then response.write "<input type='checkbox' name='checkday' value='" & (7*i-w+2)+1 & "'>
" & (7*i-w+2)+1 else response.write "-"%> </td>

<td width="80" align=center><% if (7*i-w+2)+2 > 0 and (7*i-w+2)+2 <= Days then response.write "<input type='checkbox' name='checkday' value='" & (7*i-w+2)+2 & "'>
" & (7*i-w+2)+2 else response.write "-"%> </td>

<td width="80" align=center><% if (7*i-w+2)+3 > 0 and (7*i-w+2)+3 <= Days then response.write "<input type='checkbox' name='checkday' value='" & (7*i-w+2)+3 & "'>
" & (7*i-w+2)+3 else response.write "-"%> </td>

<td width="80" align=center><% if (7*i-w+2)+4 > 0 and (7*i-w+2)+4 <= Days then response.write "<input type='checkbox' name='checkday' value='" & (7*i-w+2)+4 & "'>
" & (7*i-w+2)+4 else response.write "-"%> </td>

<td width="80" align=center><% if (7*i-w+2)+5 > 0 and (7*i-w+2)+5 <= Days then response.write "<input type='checkbox' name='checkday' value='" & (7*i-w+2)+5 & "'>
" & (7*i-w+2)+5 else response.write "-"%> </td>

<td width="80" align=center><% if (7*i-w+2)+6 > 0 and (7*i-w+2)+6 <= Days then response.write "<input type='checkbox' name='checkday' value='" & (7*i-w+2)+6 & "'>
<font color='#009900'>" & (7*i-w+2)+6 & "</font>" else response.write "-"%> </td>

</tr>

<% next %>

</table>

</form>

</div>

</body>

<script Language="Javascript">

function chk_week_day(k,wd,ds){

for (i=wd;i<ds+1;i=i+7){

if (form1.checkday[i-1].checked) {

form1.checkday[i-1].checked=false;

}else {

form1.checkday[i-1].checked=true;

}

}

}

function chk_all(ds){

for (i=0;i<ds+1;i++){

if (form1.checkday[i].checked) {

form1.checkday[i].checked=false;

}else {

form1.checkday[i].checked=true;

}

}

}

</script>

</html>

本篇文章發表於2002-08-21 00:00
目前尚無任何回覆
   

回覆
如要回應,請先登入.