读书人

Web上使用日历控件点击后弹出类似Me

发布时间: 2012-01-19 20:57:58 作者: rapoo

Web上使用日历控件,点击后弹出类似MessageBox,选择后我想取得他的返回值,大家帮帮忙啊
我需要点击日历控件上的日期,然后弹出一个类似MessageBox的对话框,有YES和NO,选择后我想取得这个返回值,大家有什么好的方法吗??我用JS脚本写能取得他的返回值,可是总是慢一步。。刷新一次后才得到他的值。有答案了马上结帖。谢谢大家了

[解决办法]
up
[解决办法]
重写RENDER方法
[解决办法]
----------------------------calendar.htm--------------------------------
<%@ Page %>
<HTML>
<HEAD>
<META NAME= "GENERATOR " Content= "Microsoft Visual Studio 6.0 " charset= "GB2312 ">
<STYLE TYPE= "text/css ">
table{font-size:9pt}
.today {BACKGROUND: #cccccc}
.satday{color:green}
.sunday{color:red}
.days {color:#777777}
.btn{width:15pt;height:14pt}
.sel{height:15pt;font-size:9pt}
</STYLE>
<SCRIPT LANGUAGE= "JavaScript ">

//All right reserved by Takemura
//中文月份,如果想显示英文月份,修改下面的注释
/*var months = new Array( "January?, "February?, "March ", "April ", "May ", "June ", "July ", "August ", "September ",
"October ", "November ", "December ");*/
var months = new Array( "一月 ", "二月 ", "三月 ", "四月 ", "五月 ", "六月 ", "七月 ", "八月 ", "九月 ", "十月 ", "十一月 ", "十二月 ");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31);

//中文周 如果想显示 英文的,修改下面的注释
/*var days = new Array( "Sunday ", "Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday ");*/
var days = new Array( "星期日 ", "星期一 ", "星期二 ", "星期三 ", "星期四 ", "星期五 ", "星期六 ");

function getDays(month, year) {
//判断当前是否是闰年
if (1 == month)
return ((0 == year % 4) && (0 != (year % 100))) ||(0 == year % 400) ? 29 : 28;
else
return daysInMonth[month];
}

function getToday() {
//得到今天的年,月,日
this.now = new Date();
this.year = this.now.getFullYear();
this.month = this.now.getMonth();
this.day = this.now.getDate();
}

today = new getToday();

//生成新日历
function newCalendar(vTemp) {
today = new getToday();
var objMonth = document.all.month
var objYear = document.all.year
var parseYear = parseInt(objYear[objYear.selectedIndex].text);
//滚动月份
if (vTemp == -1){ //前滚,处理1月
if (objMonth.selectedIndex == 0){
if (parseInt(objYear[objYear.selectedIndex].text) == today.year - 50){
return false;
}
objMonth.selectedIndex = 11;
objYear.selectedIndex = objYear.selectedIndex - 1
var newCal = new Date(parseInt(objYear[objYear.selectedIndex].text),11,1)
}else{
objMonth.selectedIndex = objMonth.selectedIndex - 1
var newCal = new Date(parseYear,objMonth.selectedIndex,1);
}
}else if (vTemp == 1){//后滚,处理12月
if (objMonth.selectedIndex == 11){
if (parseInt(objYear[objYear.selectedIndex].text) == today.year + 8 - 1){
return false;
}
objMonth.selectedIndex = 0;
objYear.selectedIndex = objYear.selectedIndex + 1
var newCal = new Date(parseInt(objYear[objYear.selectedIndex].text),0,1)
}else{
objMonth.selectedIndex = objMonth.selectedIndex + 1
var newCal = new Date(parseYear,objMonth.selectedIndex ,1);
}


}else{ //缺省
var newCal = new Date(parseYear,objMonth.selectedIndex, 1);
}

var day = -1;
var startDay = newCal.getDay();
var daily = 0;
if ((today.year == newCal.getFullYear()) &&(today.month == newCal.getMonth()))
day = today.day;
var tableCal = document.all.calendar.tBodies.dayList;
var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear());
for (var intWeek = 0; intWeek < tableCal.rows.length;intWeek++)
for (var intDay = 0;intDay < tableCal.rows[intWeek].cells.length;intDay++)
{
var cell = tableCal.rows[intWeek].cells[intDay];
if ((intDay == startDay) && (0 == daily))
daily = 1;
if(day==daily)
//今天,调用今天的Class
cell.className = "today ";
else if(intDay==6)
//周六
cell.className = "sunday ";
else if (intDay==0)
//周日
cell.className = "satday ";
else
//平常
cell.className= "normal ";

if ((daily > 0) && (daily <= intDaysInMonth))
{
cell.innerText = daily;
daily++;
}
else
cell.innerText = " ";
}
}

function ChangeBGColor(temp){
var tableCal = document.all.calendar.tBodies.dayList;
var cell = tableCal.rows[2].cells[4];
cell.bgcolor= "#123456 "
}

function getDate() {
var sDate;
//处理鼠标点击,数据输出接口
if ( "TD " == event.srcElement.tagName)
if ( " " != event.srcElement.innerText)
{
sDate = document.all.year.value + "- " + document.all.month.value + "- " + event.srcElement.innerText ;
window.returnValue = sDate;

window.close();

}
}

</SCRIPT>
</HEAD>
<BODY ONLOAD= "newCalendar() ">
<input type= "hidden " name= "ret ">
<!--日历部分-->
<!--===================================================================================================================-->
<table border= "1 ">
<tr>
<td>
<TABLE ID= "calendar " cellspacing= "0 " cellpadding= "0 " width= "310 " bgcolor= "#ededed ">
<THEAD bgcolor= "#cccccc ">
<TR height= "30 ">
<TD COLSPAN= "7 " ALIGN= "CENTER ">
<input type= "button " id= "previous " class= "btn " value= "← " onclick= "newCalendar(-1) ">
<!--月份-->
<SELECT ID= "month " class= "sel " ONCHANGE= "newCalendar(0) ">
<SCRIPT LANGUAGE= "JavaScript ">
for (var intLoop = 0; intLoop < months.length;intLoop++)
document.write( " <OPTION VALUE= " + (intLoop + 1) + " " +(today.month == intLoop ? "Selected " : " ") + "> " +months[intLoop]);
</SCRIPT>
</SELECT>
<!--年度-->
<SELECT ID= "year " class= "sel " ONCHANGE= "newCalendar(0) ">
<SCRIPT LANGUAGE= "JavaScript ">
for (var intLoop = today.year-50; intLoop < (today.year + 8);intLoop++)
document.write( " <OPTION VALUE= " + intLoop + " " +(today.year == intLoop ? "Selected " : " ") + "> " +intLoop);
</SCRIPT>
</SELECT>
<input type= "button " id= "next " class= "btn " value= "→ " onclick= "newCalendar(1) ">


</TD>
</TR>
</THEAD>
<!--星期-->
<TR CLASS= "days " height= "25 " valign= "bottom " align= "center ">
<SCRIPT LANGUAGE= "JavaScript ">
document.write( " <TD class=satday> " + days[0] + " </TD> ");
for (var intLoop = 1; intLoop < days.length-1;intLoop++)
document.write( " <TD> " + days[intLoop] + " </TD> ");
document.write( " <TD class=sunday> " + days[intLoop] + " </TD> ");
</SCRIPT>
</TR>
<TR>
<TD colspan= "7 " align= "center "> <HR size= "1 " width= "300 " noShade>
</TD>
</TR>
<!--日期-->
<TBODY border= "1 " cellspacing= "0 " cellpadding= "0 " ID= "dayList " ONCLICK= "getDate() " ALIGN= "CENTER ">
<SCRIPT LANGUAGE= "JavaScript ">
for (var intWeeks = 0; intWeeks < 6; intWeeks++) {
document.write( " <TR style= 'cursor:hand '> ");
for (var intDays = 0; intDays < days.length;
intDays++)
document.write( " <TD id=Day " + intDays + " onmouseover=this.style.backgroundColor= '#cccccc ' onmouseout=this.style.backgroundColor= ' '> </TD> ");
document.write( " </TR> ");
}
</SCRIPT>
</TBODY>
</TABLE>
</td>
</tr>
</table>
</BODY>
</HTML>

------------------------------------Calendar.js---------------
// JScript 文件

function ShowCalendar(objInput)
{
var vReturnValue = showModalDialog( "calendar.htm ", " ", "dialogWidth:330px;dialogHeight:202px;status:no;center:true;help:no ");
if (vReturnValue!= " " && vReturnValue!=null)
{
objInput.value = vReturnValue;
}
}

------------------------------页面调用------------------
<asp:TextBox ID= "TextBox1 " runat= "server " onclick= "ShowCalendar(this) "> </asp:TextBox>

后台
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox1.Attributes[ "readonly "] = "true ";//为了让用户只能选,注册readonly
}
}

读书人网 >asp.net

热点推荐