⑴ JavaScript訪問時間限制問題
if寫法錯了
function clowin(){
var today=new Date()
var h=today.getHours()
if(0<=h && h<=6){
//if(0<=h<=6){
alert('親愛的朋友,現在是休息時間,暫時不能訪問主頁!');
history.back();
}
else if(22<=h && h<=24){
//else if(22<=h<=24){
alert('親愛的朋友,現在是休息時間,暫時不能訪問主頁!');
history.back();
}
}
-------------------------------------------
if(0<=h && h<=6)
else if(22<=h && h<=24)
⑵ js中日期格式控制,請教大家
直接的話是不行的,需要進行計算。
下面有個參考的示例
<html>
<head>
<title>日期判斷 周 月 季 年</title>
<script type="text/javascript">
var getMonthWeek = function (a, b, c) {
var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate();
return Math.ceil( (d + 6 - w) / 7 );
};
var getYearWeek = function (a, b, c) {
var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1),
d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000);
return Math.ceil( (d + ((date2.getDay() + 1) - 1)) / 7 );
};
var today = new Date();//獲取當前時間
var y = today.getFullYear();
var m = today.getMonth()+1;
var d = today.getDate();
document.write("今天是:",y,"-", m, "-", d, "<br/>");
document.write( "今天是",y,"年的第 ", getYearWeek(y, m, d), " 周<br/>" );
document.write( "今天是",m,"月的第 ", getMonthWeek(y, m, d), " 周<br/>" );
var quarter = "";
var result = getYearWeek(y, m, d);
if (m <4) {
quarter = 1;
week = result;
} else if (m < 7) {
quarter = 2;
week = result - getYearWeek(y, 4, 1);
var day = new Date(y, 4, 1);
if (day.getDay() > 1) {
week += 1;
}
} else if (m < 10) {
quarter = 3;
week = result - getYearWeek(y, 7, 1);
var day = new Date(y, 7, 1);
if (day.getDay() > 1) {
week += 1;
}
} else {
quarter = 4;
week = result - getYearWeek(y, 10, 1);
var day = new Date(y, 10, 1);
if (day.getDay() > 1) {
week += 1;
}
}
document.write( "今天是第",quarter,"季度的第 ", week, " 周" );
</script>
</head>
<body>
</body>
</html>
⑶ 請問js如何控制輸入日期范圍在一個月之內
var d1 = document.getElementById("Text1").value;
var myDate1 = new Date();
myDate1.setFullYear(d1.substring(0, 4), d1.substring(4, 6), d1.substring(6));
var d2 = document.getElementById("Text2").value;
var myDate2 = new Date();
myDate2.setFullYear(d2.substring(0, 4), d2.substring(4, 6), d2.substring(6));
alert((myDate2 - myDate1)/86400000);
⑷ js日期控制項 限制選擇日期(只能選擇指定日期)
js日期控制項 限制選擇日期(只能選擇指定日期)
日期空間 貌似都有限制的功能
⑸ 如何用js來對輸入日期的時間范圍進行限制
把你的字元串分成年、月、日三部分,轉成數字
然後用 var time=new Date(年,月,日); 來取得時間,再進行比較操作。注意月是0到11范圍
⑹ js驗證日期間隔不能大於一個月
還是你啊
剛才我也沒想到
這樣改:
var d1="20110911";
var d2="20111012";
var h1=parseInt(d1.substring(4,6),10);//轉換成10進制int類型
var h2=parseInt(d2.substring(4,6),10);
alert(h2-h1);
if(h2-h1)>1
{
//你的代碼
}
你要判斷下年份,不然到年末出錯
⑺ 求高手的JavaScript日期校驗。要求起始日期不得大於結束日期。日期格式為:dd/mm/yyyy
<script type="text/javascript">
function today(){
var dd, ss="";
dd = new Date();
ss += dd.getYear()+"/";
ss += (dd.getMonth() + 1) + "/";
ss += dd.getDate();
return ss;
}
function comptime(beginTime,endTime){
var beginTimes=beginTime.substring(0,10).split('/');
var endTimes=endTime.substring(0,10).split('/');
beginTime=beginTimes[1]+'/'+beginTimes[2]+'/'+beginTimes[0]+' '+beginTime.substring(10,19);
endTime=endTimes[1]+'/'+endTimes[2]+'/'+endTimes[0]+' '+endTime.substring(10,19);
var a =(Date.parse(endTime)-Date.parse(beginTime))/3600/1000;
if(a<0){
return -1;
}else if (a>0){
return 1;
}else if (a==0){
return 0;
}else{
return 'exception'
}
}
alert(comptime("2010/01/01",today()));
alert(comptime("2010/08/01",today()));
</script>
++++++++++++++++++++++++++++++++++++++++
我已經寫出了時間對比的函數,你只需要把想要對比的時間放入函數跑一下就行了,有更多問題,可以直接HI我,。。。
至於樓主的時間格式,可以在這個JS里邊改下時間順序即可。。。。
記得加分。。。
⑻ 求限制時間段訪問頁面的JS代碼
<SCRIPT LANGUAGE="JavaScript">
<!--
var d, s ;
d = new Date();
s = d.getDate() ;
if(s>17 || s<15){
alert("現在是上班時間。。。。。。");
window.close();
}
//-->
</SCRIPT>
測試無錯誤。
滿意請採納!
⑼ js驗證日期格式mm-dd-yyyy,例如月份不要超過12
<!DOCTYPEHTML>
<html>
<head>
<metacharset="UTF-8"/>
<title>JS</title>
<STYLE>
</STYLE>
<scripttype="text/javascript">
window.onload=function()
{
vardate=newDate,year=date.getFullYear();
if(year%400==0||year%4==0&&year%100!=0)
{
alert('今年是閏年');
}
else
{
alert('今年不是閏年');
}
varreg=/^(0[1-9]|1[0-2])-(0[1-9]|[12]d|3[01])-[1-9]d{3}$/;
varstr="12-01-2011";
alert(reg.test(str));
str="13-01-2011";
alert(reg.test(str));
}
</script>
</head>
<body>
</body>
</html>