多个datepicker [英] Multiple datepicker

查看:75
本文介绍了多个datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我试图在网页中引入多个日期选择器,并且第二个选择器出现了

问题。我试图复制和修改第一个使用的代码我用了b $ b,重命名变量,但它根本无法输出任何日期到数据库。第一个选择器的代码(

工作正常)如下:


< html>

< head> ;

< script type =" text / javascript">


var numDays = {

''1' ':31,''''':28,''3'':31,''4'':30,''5'':31,''6'':30,

''7'':31,''8'':31,''9'':30,''10'':31,''11'':30,''12'':31 < br $>
};


函数setDays(oMonthSel,oDaysSel,oYearSel)

{

var nDays, oDaysSelLgth,opt,i = 1;

nDays = numDays [oMonthSel [oMonthSel.selectedIndex] .value];

if(nDays == 28&& oYearSel [ oYearSel.selectedIndex] .value%4 == 0)

++ nDays;

oDaysSelLgth = oDaysSel.length;

if(nDays! = oDaysSelLgth)

{

if(nDays< oDaysSelLgth)

oDaysSel.length = nDays;

else for(i; i< nDays - oDaysSelLgth + 1; i ++)

{

opt = new Option(oDaysSelLgth + i,oDaysSelLgth + i);

oDaysSel.options [ oDaysSel.length] = opt;

}

}

var oForm = oMonthSel.form;

var month = oMonthSel.options [oMonthSel.selectedIndex] .value;

var day = oDaysSel.options [oDaysSel.selectedIndex] .value;

var year = oYearSel.options [oYearSel .selectedIndex] .value;

oForm.f_despara.value = month +''/''+ day +''/''+ year;

}

< / head>

< body>

< form>

< table>

< tr>

< td>

< select name =" day"类= QUOT; buscar" id =" day"

onChange =" setDays(month,this,year)">

< option value =" 1"> 1< ; / option>

< option value =" 2"> 2< / option>

< option value =" 3"> 3< /选项>

< option value =" 4"> 4< / option>

< option value =" 5"> 5< / option>

< option value =" 6"> 6< / option>

< option value =" 7"> 7< / option>

< option value =" 8"> 8< / option>

< option value =" 9"> 9< / option>

< option value =" 10"> 10< / option>

< option value =" 11"> 11< / option>

< option value =" 12"> 12< / option>

< option value =" 13"> 13< / option>

< option value =" 14"> 14< / option>

< option value =" 15" > 15< / option>

< option value =" 16"> 16< / option>

< option value =" 17"> 17< / option>

< option value =" 18"> 18< / option>

< option value =" 19"> 19< / option>

< option value =" 20"> 20< / option>

< option value =" 21"> 21< / option> ;

< option value =" 22"> 22< / option>

< option value =" 23"> 23< / option>

< option value =" 24"> 24< / option>

< option value =" 25"> 25< / option>

< option value =" 26"> 26< / option>

< option value =" 27"> 27< / option>

< option value =" 28"> 28< / option>

< option value =" 29"> 29< / option>

< option value =" 30"> 30< / option>

< opt ion value =" 31"> 31< / option>

<选择的选项> D& iacute; a< / option>

< / select>< ; / td>

< td>< select name =" month"类= QUOT; buscar" id =" month"

onchange =" setDays(this,day,year)">

< option value =" 1"> Enero< ; / option>

< option value =" 2"> Febrero< / option>

< option value =" 3"> Marzo< /选项>

< option value =" 4"> Abril< / option>

< option value =" 5"> Mayo< / option>

< option value =" 6"> Junio< / option>

< option value =" 7"> Julio< / option>

< option value =" 8"> Agosto< / option>

< option value =" 9"> Septiembre< / option>

< option value =" 10"> Octubre< / option>

< option value =" 11"> Noviembre< / option>

< option value =" 12"> Diciembre< / option>

<选择的选项> Mes< / option>

< / select>< ; / td>

< td >< select name =" year"类= QUOT; buscar" id =" year"

onchange =" setDays(month,day,this)">

< option value =" 1995"> 1995< ; / option>

< option value =" 1996"> 1996< / option>

< option value =" 1997"> 1997< /选项>

< option value =" 1998"> 1998< / option>

< option value =" 1999"> 1999< / option>

< option value =" 2000"> 2000< / option>

< option value =" 2001"> 2001< / option>

< option value =" 2002"> 2002< / option>

< option value =" 2003"> 2003< / option>

< option value =" 2004"> 2004< / option>

<选择的选项> A& ntilde; o< / option>

< / select>

< input type =" hidden"名称= QUOT; f_despara"值= QUOT;" />

< / td>

< / tr>

< / table>

< / form>

< / body>

< / html>



然后我试过添加第二个日期选择器,从未工作过。我试过这种方式:

我在脚本中添加了另一个函数:


函数setDays2(oMonth2Sel,oDays2Sel,oYear2Sel)

{

var nDays2,oDays2SelLgth,opt2,i2 = 1;

nDays2 = numDays [oMonth2Sel [oMonth2Sel.selectedIndex] .value];

if(nDays2 == 28&& oYear2Sel [oYear2Sel.selectedIndex] .value%4 == 0)

++ nDays2;

oDays2SelLgth = oDays2Sel.length;

if(nDays2!= oDays2SelLgth)

{

if(nDays2< oDays2SelLgth)

oDays2Sel.length = nDays2;

else for(i2; i2< nDays2 - oDays2SelLgth + 1; i2 ++)

{

opt = new Option(oDays2SelLgth + i2,oDays2SelLgth + i2);

oDays2Sel.options [oDays2Sel.length] = opt2;

}

}

var oForm2 = oMonth2Sel.form;

var month2 = oMonth2Sel.options [oMonth2Sel.selectedIndex] .value;

var day2 = oDays2Sel.options [oDays2Sel.selectedIndex ] .value;

var year2 = oYear2Sel.options [oYear2Sel.selectedIndex] .value;

oForm.f_vac1.value = month2 +''/''+ day2 +''/''+ year2;

}


然后将日期选择器字段添加到表单中:


< tr>

< td>< select name =" day2"类= QUOT; buscar" id =" day2"

onChange =" setDays2(month2,this,year2)">

< option value =" 1"> 1< ; / option>

< option value =" 2"> 2< / option>

< option value =" 3"> 3< /选项>

< option value =" 4"> 4< / option>

< option value =" 5"> 5< / option>

< option value =" 6"> 6< / option>

< option value =" 7"> 7< / option>

< option value =" 8"> 8< / option>

< option value =" 9"> 9< / option>

< option value =" 10"> 10< / option>

< option value =" 11"> 11< / option>

< option value =" 12"> 12< / option>

< option value =" 13"> 13< / option>

< option value =" 14"> 14< / option>

< option value =" 15&q uot;> 15< / option>

< option value =" 16"> 16< / option>

< option value =" 17" > 17< / option>

< option value =" 18"> 18< / option>

< option value =" 19"> 19< / option>

< option value =" 20"> 20< / option>

< option value =" 21"> 21< / option>

< option value =" 22"> 22< / option>

< option value =" 23"> 23< / option> ;

< option value =" 24"> 24< / option>

< option value =" 25"> 25< / option>

< option value =" 26"> 26< / option>

< option value =" 27"> 27< / option>

< option value =" 28"> 28< / option>

< option value =" 29"> 29< / option>

< option value =" 30"> 30< / option>

< ;选项值=" 31"> 31< /选项>

<选择的选项> D& iacute; a< / option>

< / select> < / td>

< td>< select name =" month2"类= QUOT; buscar" id =" month2"

onchange =" setDays2(this,day2,year2)">

< option value =" 1"> Enero< ; / option>

< option value =" 2"> Febrero< / option>

< option value =" 3"> Marzo< /选项>

< option value =" 4"> Abril< / option>

< option value =" 5"> Mayo< / option>

< option value =" 6"> Junio< / option>

< option value =" 7"> Julio< / option>

< option value =" 8"> Agosto< / option>

< option value =" 9"> Septiembre< / option>

< option value =" 10"> Octubre< / option>

< option value =" 11"> Noviembre< / option>

< option value =" 12"> Diciembre< / option>

<选择的选项> Mes< / option>

< / select>< ; / td>

&l t; td>< select name =" year2"类= QUOT; buscar" id =" year2"

onchange =" setDays2(month2,day2,this)">

< option value =" 1995"> 1995< ; / option>

< option value =" 1996"> 1996< / option>

< option value =" 1997"> 1997< /选项>

< option value =" 1998"> 1998< / option>

< option value =" 1999"> 1999< / option>

< option value =" 2000"> 2000< / option>

< option value =" 2001"> 2001< / option>

< option value =" 2002"> 2002< / option>

< option value =" 2003"> 2003< / option>

< option value =" 2004"> 2004< / option>

<选择的选项> A& ntilde; o< / option>

< / select>

< input type =" hidden"名称= QUOT; f_vac1"值= QUOT;" />

< / td>

< / tr>


该脚本可以很好地避免表单但从未将

值传递给数据库。


有人可以帮助我吗?


提前致谢,


Gustavo

Hi,

I am trying to introduce a multiple datepicker into a webpage and the
problem arises with the second picker. I tried to copy and adapt the code I
employed for the first one, renaming the variables but it is simply unable
to output any date to the database. The code for the first picker (which
works fine) is as follows:

<html>
<head>
<script type="text/javascript">

var numDays = {
''1'': 31, ''2'': 28, ''3'': 31, ''4'': 30, ''5'': 31, ''6'': 30,
''7'': 31, ''8'': 31, ''9'': 30, ''10'': 31, ''11'': 30, ''12'': 31
};

function setDays(oMonthSel, oDaysSel, oYearSel)
{
var nDays, oDaysSelLgth, opt, i = 1;
nDays = numDays[oMonthSel[oMonthSel.selectedIndex].value];
if (nDays == 28 && oYearSel[oYearSel.selectedIndex].value % 4 == 0)
++nDays;
oDaysSelLgth = oDaysSel.length;
if (nDays != oDaysSelLgth)
{
if (nDays < oDaysSelLgth)
oDaysSel.length = nDays;
else for (i; i < nDays - oDaysSelLgth + 1; i++)
{
opt = new Option(oDaysSelLgth + i, oDaysSelLgth + i);
oDaysSel.options[oDaysSel.length] = opt;
}
}
var oForm = oMonthSel.form;
var month = oMonthSel.options[oMonthSel.selectedIndex].value;
var day = oDaysSel.options[oDaysSel.selectedIndex].value;
var year = oYearSel.options[oYearSel.selectedIndex].value;
oForm.f_despara.value = month + ''/'' + day + ''/'' + year;
}
</head>
<body>
<form>
<table>
<tr>
<td>
<select name="day" class="buscar" id="day"
onChange="setDays(month,this,year)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<option selected>D&iacute;a</option>
</select></td>
<td><select name="month" class="buscar" id="month"
onchange="setDays(this,day,year)">
<option value="1">Enero</option>
<option value="2">Febrero</option>
<option value="3">Marzo</option>
<option value="4">Abril</option>
<option value="5">Mayo</option>
<option value="6">Junio</option>
<option value="7">Julio</option>
<option value="8">Agosto</option>
<option value="9">Septiembre</option>
<option value="10">Octubre</option>
<option value="11">Noviembre</option>
<option value="12">Diciembre</option>
<option selected>Mes</option>
</select></td>
<td><select name="year" class="buscar" id="year"
onchange="setDays(month,day,this)">
<option value="1995">1995</option>
<option value="1996">1996</option>
<option value="1997">1997</option>
<option value="1998">1998</option>
<option value="1999">1999</option>
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option selected>A&ntilde;o</option>
</select>
<input type="hidden" name="f_despara" value="" />
</td>
</tr>
</table>
</form>
</body>
</html>


Then I tried to add a second date picker and never worked. I tried this way:
I added another function to the script:

function setDays2(oMonth2Sel, oDays2Sel, oYear2Sel)
{
var nDays2, oDays2SelLgth, opt2, i2 = 1;
nDays2 = numDays[oMonth2Sel[oMonth2Sel.selectedIndex].value];
if (nDays2 == 28 && oYear2Sel[oYear2Sel.selectedIndex].value % 4 == 0)
++nDays2;
oDays2SelLgth = oDays2Sel.length;
if (nDays2 != oDays2SelLgth)
{
if (nDays2 < oDays2SelLgth)
oDays2Sel.length = nDays2;
else for (i2; i2 < nDays2 - oDays2SelLgth + 1; i2++)
{
opt = new Option(oDays2SelLgth + i2, oDays2SelLgth + i2);
oDays2Sel.options[oDays2Sel.length] = opt2;
}
}
var oForm2 = oMonth2Sel.form;
var month2 = oMonth2Sel.options[oMonth2Sel.selectedIndex].value;
var day2 = oDays2Sel.options[oDays2Sel.selectedIndex].value;
var year2 = oYear2Sel.options[oYear2Sel.selectedIndex].value;
oForm.f_vac1.value = month2 + ''/'' + day2 + ''/'' + year2;
}

and then added the date picker fields to the form:

<tr>
<td><select name="day2" class="buscar" id="day2"
onChange="setDays2(month2,this,year2)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<option selected>D&iacute;a</option>
</select></td>
<td><select name="month2" class="buscar" id="month2"
onchange="setDays2(this,day2,year2)">
<option value="1">Enero</option>
<option value="2">Febrero</option>
<option value="3">Marzo</option>
<option value="4">Abril</option>
<option value="5">Mayo</option>
<option value="6">Junio</option>
<option value="7">Julio</option>
<option value="8">Agosto</option>
<option value="9">Septiembre</option>
<option value="10">Octubre</option>
<option value="11">Noviembre</option>
<option value="12">Diciembre</option>
<option selected>Mes</option>
</select></td>
<td><select name="year2" class="buscar" id="year2"
onchange="setDays2(month2,day2,this)">
<option value="1995">1995</option>
<option value="1996">1996</option>
<option value="1997">1997</option>
<option value="1998">1998</option>
<option value="1999">1999</option>
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option selected>A&ntilde;o</option>
</select>
<input type="hidden" name="f_vac1" value="" />
</td>
</tr>

The script works well avoiding invalid date on the form but never passes the
value to the database.

Could someone help me?

Thanks in advance,

Gustavo

推荐答案

Simon Templar写道:
Simon Templar wrote:
< html> ;


这不是有效的HTML。 < http://validator.w3.org/>

< head>
< script type =" text / javascript">
var numDays = {
''1'':31,''2'':28,


在闰年,2月有29天。


''3'':31,''4'':30,''5'':31,''6'':30,''7'':31,'' 8'':31,''9'':30,''10'':31,''11'':30,''12'':31
};
<html>
This is not Valid HTML. <http://validator.w3.org/>
<head>
<script type="text/javascript">

var numDays = {
''1'': 31, ''2'': 28,
In leap years, February has 29 days.

''3'': 31, ''4'': 30, ''5'': 31, ''6'': 30, ''7'': 31, ''8'': 31, ''9'': 30, ''10'': 31, ''11'': 30, ''12'': 31
};



使用Date对象可以可靠地确定一个月的天数(包括

闰年):


/ **

*返回一个月的天数。

*

* @author

*( C)2004 Thomas Lahn< da ***** @ PointedEars.de>

* @partof

*< http://pointedears.de/scripts/ date.js>

* @argument日期d

*保留月份的日期对象。

* @return类型编号

* d的数量当月没有,
如果没有通过Date对象,则
* -1。

* /

函数getDaysOfMonth(d)

{

if(d&& d.constructor == Date)

{

//制作一份复制品传递的Date对象,以便它不会改变

var y;

if(d.getFullYear)

{

y = d.getFullYear();

}

else

{

y = d.getYear( );

if(y <1900)

{
$ b $ + = 1900;

}

}


var d2 =新日期(y,d.getMonth()+ 1,d.getDate());


//下个月第一天前一天

//是当月的最后一天

d2.setDate(0);


返回d2.getDate();

}


返回-1;

对于其余的源代码,我建议你将一个测试用例放在一个有效的
HTML文档中(如果它包含服务器端脚本,请输入源代码

在未解析的HTML文档[.phps之类]或文本文件中)

而不是倾销超过200个未注释的(有些甚至是不必要的)

到公共新闻组的行。
PointedEars



The number of days a month has can be determined reliably (including
leap years) using Date objects:

/**
* Returns the number of days of a month.
*
* @author
* (C) 2004 Thomas Lahn <da*****@PointedEars.de>
* @partof
* <http://pointedears.de/scripts/date.js>
* @argument Date d
* Date object to hold the month.
* @return type number
* The number of the days of the month,
* -1 if no Date object has been passed.
*/
function getDaysOfMonth(d)
{
if (d && d.constructor == Date)
{
// make a "copy" of the passed Date object so that it does not change
var y;
if (d.getFullYear)
{
y = d.getFullYear();
}
else
{
y = d.getYear();
if (y < 1900)
{
y += 1900;
}
}

var d2 = new Date(y, d.getMonth() + 1, d.getDate());

// the day before the first day of the next month
// is the last day of the current month
d2.setDate(0);

return d2.getDate();
}

return -1;
}
For the rest of your source code, I suggest you put a testcase in a Valid
HTML document (if it contains server-side scripting, put the source code
of that in an unparsed HTML document [.phps and the like] or a text file)
instead of dumping more than 200 uncommented (and some even unnecessary)
lines of it to a public newsgroup.
PointedEars


Thomas''PointedEars''Lahn< Po ********* @ web.de>写道:
Thomas ''PointedEars'' Lahn <Po*********@web.de> writes:
function getDaysOfMonth(d)


不妨单独传递年份和月份数,不需要完整的
date。

if(d.getFullYear)
function getDaysOfMonth(d)
Might as well pass the year and month number alone, no need for a full
date.
if (d.getFullYear)




虽然getFullYear很方便,但如果它变好了你也不会更好

即将失踪。只需:

---

函数getDaysOfMonth(年,月){//月== 1是1月

if(year> ; = 0&& year< 100){

年+ = 100;

月 - = 1200;

}

返回新日期(年,月,0).getDate();

}

---

年/月的修正似乎是必要的,否则

功能将在0年失败,因为它(以及

0和99之间的所有其他内容)将有1900添加到今年。然而,0年是闰年的b $ b(根据Javascript的Date对象),而1900

不是。


/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

DHTML死亡颜色:< URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>

''没有判断的信仰只会降低精神神圣。''



While getFullYear is convenient, you are no better off if it turns
out to be missing. Just do:
---
function getDaysOfMonth(year, month) { // month==1 is January
if (year >= 0 && year < 100) {
year += 100;
month -= 1200;
}
return new Date(year, month, 0).getDate();
}
---
The correction for year/month seems to be necessary, otherwise the
function will fail for the year 0, as it (and everything else between
0 and 99) will have 1900 added to the year. However, the year 0 was a
leap year (according to the Javascript the Date object), while 1900
wasn''t.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
''Faith without judgement merely degrades the spirit divine.''


JRS:文章< 41 ************** @ PointedEars.de>,日期为Mon ,7月26日

2004 06:28:55,见于新闻:comp.lang.javascript,托马斯''PointedEars''

Lahn< Po **** *****@web.de>发表:
JRS: In article <41**************@PointedEars.de>, dated Mon, 26 Jul
2004 06:28:55, seen in news:comp.lang.javascript, Thomas ''PointedEars''
Lahn <Po*********@web.de> posted :
Simon Templar写道:
Simon Templar wrote:
var numDays = {
''1'':31, ''2'':28,
var numDays = {
''1'': 31, ''2'': 28,



在闰年,2月有29天。



In leap years, February has 29 days.




如果你遇到麻烦在回答之前阅读Sainted的代码,

你会看到他知道这一点;他的代码与朱利安日历,AFAICS完全符合



''3'':31,''4'':30,''5 '':31,''6'':30,



If you had troubled to read the Sainted one''s code before responding,
you would have seen that he is aware of that; his code fully complies
with the Julian Calendar, AFAICS.


''3'': 31, ''4'': 30, ''5'': 31, ''6'': 30,

'''7'':31,''8'':31,''9'':30,''10'' :31,''11'':30,''12'':31
};
使用日期可以可靠地确定一个月的天数(包括闰年)对象:

/ **
*返回一个月的天数。
''7'': 31, ''8'': 31, ''9'': 30, ''10'': 31, ''11'': 30, ''12'': 31
};
The number of days a month has can be determined reliably (including
leap years) using Date objects:

/**
* Returns the number of days of a month.




仅适用于完全格里高利月,当然。


*
* @author
*(C)2004 Thomas Lahn< da ***** @ PointedEars.de>


YCKI。


y = d.getYear();
if(y< 1900)
{
y + = 1900;
}
}


在某些系统中不正确。我最近发布了,并且没有人反驳过
,这是一个简单而可靠的方法,可以从任何一个可靠的getYear()获得全年。


d2.setDate(0);



Only for fully-Gregorian months, of course.

*
* @author
* (C) 2004 Thomas Lahn <da*****@PointedEars.de>
YCKI.

y = d.getYear();
if (y < 1900)
{
y += 1900;
}
}
Incorrect in some systems. I have recently posted, and no-one has
refuted, a brief and reliable means of getting the full year from any
plausible getYear().

d2.setDate(0);




Mac NS 4可能出现故障。



这个小组最近的讨论应该已经向你表明了一个更快,更短的方法。

西蒙:见常见问题解答;它间接导致

< URL:http://www.merlyn.demon.co.uk/js-date4.htm#MaYl>其中包含


函数TailOfMonth(y,m){

如果(m == 1)返回28 +(y%4 == 0)// 1901-2099

返回[31,0,31,30,31,30,31,31,30,31,30,31] [m]}


,就像你已经拥有的一样。在我的系统上,它比我使用日期对象的最佳速度快5 / b
倍,而且这几乎是TL给出的两倍。


所有格里高利年的修改都不应该减慢太多。


BOTF。


- -

?约翰斯托克顿,英国萨里。 ?@merlyn.demon.co.uk Turnpike v4.00 IE 4?

< URL:http://jibbering.com/faq/> JL / RC:新闻常见问题解答:comp.lang.javascript

< URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr数学,日期,来源。

< URL:http://www.merlyn.demon.co.uk/> TP / BP / Delphi / jscr /& c,常见问题项目,链接。



Possible failure in Mac NS 4.


Recent discussion in this group should have indicated to you a
considerably quicker, and shorter, method.
Simon : see FAQ; it leads indirectly to
<URL:http://www.merlyn.demon.co.uk/js-date4.htm#MaYl> which has

function TailOfMonth(y, m) {
if (m==1) return 28 + (y%4 == 0) // 1901-2099
return [31,0,31,30,31,30, 31,31,30,31,30,31][m] }

which is rather like what you already have. On my system, it is about 5
times faster than the best I know using a Date Object, and that is
nearly twice as fast as one like what TL gave.

Modification for all Gregorian years should not slow it much.

BOTF.

--
? John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ?
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.


这篇关于多个datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆