日期:2014-05-16  浏览次数:20479 次

在文本框中输入日期在另一文本框中得到星期几(速度)﹗
如题:即
在一文本框中输入:2007-04-16(用日历)
另一文本框中得到:星期一


------解决方案--------------------
<script type= "text/javascript ">
function GetWeekday()
{
var weekday = new Array( "星期日 ", "星期一 ", "星期二 ", "星期三 ", "星期四 ", "星期五 ", "星期六 ");
var arrInput = document.getElementById( "t1 ").value.split( "- ");
if (arrInput.length < 3)
alert ( "error input ");
else
{
var d = new Date(arrInput[0], arrInput[1] - 1, arrInput[2]);
document.getElementById( "t2 ").value = weekday[d.getDay()];
}
}
</script>
<input type= "text " id= "t1 ">
<input type= "button " value= "go " onclick= "javascript:GetWeekday(); ">
<input type= "text " id= "t2 ">

------解决方案--------------------
验证格式的函数没写
<script type= "text/javascript ">
function GetWeekday()
{
var arrInput = document.getElementById( "t1 ").value.split( "- ");
var d = new Date(arrInput[0], arrInput[1] - 1, arrInput[2]);
document.getElementById( "t2 ").value = "星期 "+ "日一二三四五六 ".charAt(d.getDay());
}
</script>
<input type= "text " id= "t1 ">
<input type= "button " value= "go " onclick= "javascript:GetWeekday(); ">
<input type= "text " id= "t2 ">
------解决方案--------------------
<body> 格式为:2007/04/16
<input id= "txt " type= "text " onblur= "a() "> </br>
<input id= "txt1 " type= "text " value= " " >
<script language= "javascript ">
function a(){
var wek=new Array(7);
wek[0]= "星期日 ";
wek[1]= "星期一 ";
wek[2]= "星期二 ";
wek[3]= "星期三 ";
wek[4]= "星期四 ";
wek[5]= "星期五 ";
wek[6]= "星期六 ";

var txt=document.getElementById( "txt ");
var txt1=document.getElementById( "txt1 ");
var txt_value=txt.value;
alert(txt_value);
ind=(new Date(txt_value)).getDay();
txt1.value=wek[ind];
}

</script>
</body>
------解决方案--------------------
http://www.blogjava.net/mxx/archive/2006/09/27/72159.html
常用公历日期处理程序

"星期 " + "日一二三四五六 ".charAt(date.getDay());
------解决方案--------------------

function meizzWriteHead(yy,mm) //往 head 中写入当前的年与月
{ document.all.meizzYearHead.innerText = yy;
document.all.meizzMonthHead.innerText = mm;
} 

function tmpSelectYearInnerHTML(strYear) //年份的下拉框
{
if (strYear.match(/\D/)!=null){alert( "年份输入参数不是数字! ");return;}
var m = (strYear) ? strYear : new Date().getFullYear();
if (m < 1000 || m > 9999) {alert( "年份值不在 1000 到 9999 之间! ");return;}
var n = m - 10;
if (n < 1000) n = 1000;
if (n + 26 > 9999) n = 9974;
var s = " <select Author=meizz name=tmpSelectYear style= 'font-size: 12px ' "
s += "onblur= 'document.all.tmpSelectYearLayer.style.display=\ "none\ " ' "
s += "onchange= 'document.all.tmpSelectYearLayer.style.display=\ &q