高手请帮忙,为什么我这样不能调用??
高手请帮忙,为什么我这样不能调用??
楼主king_cai()2006-07-12 09:47:44 在 Web 开发 / JavaScript 提问 "<td colspan=2 height=100% align=lift onclick="preMonth()" style="cursor:pointer">上月</td>"
function preMonth(){
var curr_month = getselectedMonth();
var curr_year = getselectedYear();
if(curr_month <= 0){
curr_month = 11;
curr_year--;
}
else curr_month--;
var url = setUrlParam(document.location.href,"year",curr_year);
url = setUrlParam(url,"month",curr_month);
return url;
}
为什么我点 上月的时候 onclick没有调用到preMonth()这个函数
问题点数:0、回复次数:15Top
1 楼xishanlang2001(西山狼2000)回复于 2006-07-12 10:05:08 得分 0
楼主给一下完整一点的代码Top
2 楼king_cai()回复于 2006-07-12 10:16:37 得分 0
function drawCal(firstDay,lastDate,date,monthName,year)
{
//constant table settings
var headerHeight=50 //height of the table"s beader cell
var border=2 //3D height of table"border
var cellspacing=4 //widthof table"s border
var headerColor="midnightblue" //colorof table"s header
var headerSize="+3" //size of tables header font
var colWidth=60 //widthof columns in table
var dayCellHeight=25 //heigth of cells containing days of the week
var dayColor="darkblue" //color of font representing week days
var cellHeight=40 //height of cells representing dates in the calendar
var timeColor="purple" //color of font representing current time
var todayColor="red"
//create basic table structure
// var text="" //initialize accumulative variable to empty string
// text+="<input type=text name=timeselect id=timeselect size=50 style="position:relative;top:-3px;left:375px;" >"
// text+="<input type=button id=btnselect size=2 style="position:relative;top:-3px;left:375px;">"
text+="<CENTER>"
text+="<TABLE BORDER="+border+" CELLSPACING="+cellspacing+">" //table settings
//text+="<tr height=20px><td colspan=7><input type=text name=timeselect id=timeselect size=50></td></tr>"
text+="<Tr HEIGHT="+headerHeight+">" //create table header cell
text+="<td colspan=2 height=100% align=lift onclick="preMonth()" style="cursor:pointer">上月</td>"
text+="<td colspan=3 height=100%> <FONT COLOR=""+headerColor+"" SIZE="+headerSize+">" //set font for table header
text+=monthName+""+year
text+="</FONT></td>" //close table header"s font setting
text+="<td colspan=2 height=100% align=right><a href="+nextMonth()+">下月</a></td>"
text+="</Tr>" //close header cell
//variables to hold constant settings
var openCol="<TD WIDTH="+colWidth+"HEIGHT="+dayCellHeight+">"
openCol+="<FONT COLOR=""+dayColor+"">"
var closeCol="</FONT></TD>"
//create array of abbreviated day names
//得到星期几的名称
var weekDay=new Array(8)
weekDay="星期天";
weekDay="星期一";
weekDay="星期二";
weekDay="星期三";
weekDay="星期四";
weekDay="星期五";
weekDay="星期六";
//create first row of table to set column width and specitfy week day
text+="<TR ALIGN="center" VALIGN="center">"
for(var dayNum=0;dayNum<7;++dayNum)
{
text+=openCol+weekDay+closeCol
}
text+="</TR>"
//declaration and initialization of two variables to help with tables
var digit =1
var curCell=1
//将日期摆放在日历上
var rownum=Math.ceil((lastDate+firstDay-1)/7);
for(var row=1;row<=rownum;++row)
{
text+="<TR ALIGN="right" VALIGN="top">"
for(var col=1;col<=7;++col)
{
if(digit>lastDate)
{
break
}
if(curCell<firstDay)
{
text+="<TD></TD>"
curCell++
}
else
{
if(digit==date) //current cell represent today"s date
{
text+="<TD HEIGHT=""+cellHeight+"" onclick=showTime("+digit+") style="cursor:pointer">"
text+="<FONT COLOR=""+todayColor+"">"
text+=digit
text+="</FONT><BR>"
text+="<FONT COLOR=""+timeColor+""SIZE=2>"
text+="<CENTER>"+getTime()+"</CENTER>"
text+="</FONT>"
text+="</TD>"
}
else{
text+="<TD HEIGHT="+cellHeight+" onclick=showTime("+digit+") style="cursor:pointer">"+digit+"</TD>"
}
digit++
}
}
text+="</TR>"
}
//close all basic table tags
text+="</TABLE>"
text+="</CENTER>"
document.all.tempDiv.innerHTML = text
}
Top
3 楼kabakaba(echo "kabakaba";)回复于 2006-07-12 10:16:49 得分 0
???
不明白!Top
4 楼king_cai()回复于 2006-07-12 10:18:26 得分 0
我调用的那个函数返回的是一个超链接,问题可能就出在这里,如果返回不用超链接,应该怎么改?
Top
5 楼king_cai()回复于 2006-07-12 10:19:29 得分 0
function preMonth(){
var curr_month = getselectedMonth();
var curr_year = getselectedYear();
if(curr_month <= 0){
curr_month = 11;
curr_year--;
}
else curr_month--;
var url = setUrlParam(document.location.href,"year",curr_year);
url = setUrlParam(url,"month",curr_month);
return url;
}Top
6 楼xishanlang2001(西山狼2000)回复于 2006-07-12 10:23:26 得分 0
应该不是没有调用到的问题吧.
楼主在preMonth里加上alert()试试Top
7 楼king_cai()回复于 2006-07-12 10:35:22 得分 0
调用到了的,我试过了,如果text+="<td colspan=2 height=100% align=right><a href="+preMonth()+">上月</a></td>" 这样就没有问题的,但是有一个不好的地方就是要刷新一下,所以想用onclick试试,但是preMonth返回的是超链接,所以onclick不行了,有什么其它方法吗
Top
8 楼xishanlang2001(西山狼2000)回复于 2006-07-12 10:59:45 得分 0
href="javascript:preMonth()"Top
9 楼king_cai()回复于 2006-07-12 11:13:07 得分 0
编译通不过Top
10 楼xishanlang2001(西山狼2000)回复于 2006-07-12 11:15:16 得分 0
那肯定是别的地方出问题了.
href="javascript:xxx()"
这样的写法本身肯定是没问题的.Top
11 楼king_cai()回复于 2006-07-12 11:17:32 得分 0
href="javascript:xxx()" 这样写是对的,编译能通过,但是不能调用,我用alert() 试了
Top
12 楼king_cai()回复于 2006-07-12 11:18:29 得分 0
非常感谢西山狼的关注啊Top
13 楼king_cai()回复于 2006-07-12 11:22:58 得分 0
function preMonth(){
var curr_month = getselectedMonth();
var curr_year = getselectedYear();
if(curr_month <= 0){
curr_month = 11;
curr_year--;
}
else curr_month--;
var url = setUrlParam(document.location.href,"year",curr_year);
url = setUrlParam(url,"month",curr_month);
return url;
/*var now=new Date()
var monthName=getMonthName(curr_month)
var date=now.getDate()
now = null
var firstDayInstance=new Date(curr_year,curr_month,1)
var firstDay=firstDayInstance.getDay()
firstDayInstance=null
window.alert("premonth")
window.alert(curr_month)
var days=getDays(curr_month,curr_year)
drawCal(firstDay+1,days,date,monthName,(curr_year<100)?1900+curr_year:curr_year)
*/
}
function getselectedMonth(){
var url = document.location.href;
var month = getUrlParam(url,"month");
if( month == ""){
var now = new Date();
month = now.getMonth();
}
window.alert("getselectedMonth")
window.alert(month)
return month;
}
function getselectedYear(){
var url = document.location.href;
var year = getUrlParam(url,"year");
if( year == ""){
var now = new Date();
year = now.getYear();
}
window.alert("year")
return year;
}
function getUrlParam(url, param)
{
var re = new RegExp("(\\\?|&)" + param + "=(+)(&|$)", "i");
var m = url.match(re);
if (m)
return m;
else
return "";
}
function setUrlParam(url, param, v)
{
var re = new RegExp("(\\\?|&)" + param + "=(+)(&|$)", "i");
var m = url.match(re);
if (m)
{
return (url.replace(re, function($0, $1, $2) { return ($0.replace($2, v)); } ));
}
else
{
if (url.indexOf("?") == -1)
return (url + "?" + param + "=" + v);
else
return (url + "&" + param + "=" + v);
}
}Top
14 楼kabakaba(echo "kabakaba";)回复于 2006-07-12 11:32:05 得分 0
我试了一下,完全可以的阿
Top
15 楼king_cai()回复于 2006-07-12 13:08:15 得分 0
你是用什么方法试的啊 onclick调用吗?还是用a herf调用啊Top
-
相关文章
2秒记住本站域名
玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的ReadyGo.com.cn
