您的位置:程序门 -> .net技术 -> asp.net



web上使用日历控件,点击后弹出类似messagebox,选择后我想取得他的返回值,大家帮帮忙啊


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


web上使用日历控件,点击后弹出类似messagebox,选择后我想取得他的返回值,大家帮帮忙啊[已结贴,结贴人:arbbie]
发表于:2007-08-05 10:11:24 楼主
我需要点击日历控件上的日期,然后弹出一个类似messagebox的对话框,有yes和no,选择后我想取得这个返回值,大家有什么好的方法吗??我用js脚本写能取得他的返回值,可是总是慢一步。。刷新一次后才得到他的值。有答案了马上结帖。谢谢大家了
发表于:2007-08-05 19:16:331楼 得分:5
up
发表于:2007-08-06 11:44:222楼 得分:5
重写render方法
发表于:2007-08-06 11:56:033楼 得分:20
----------------------------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
                }
        }



快速检索

最新资讯
热门点击