Posted in jQuery onJanuary 09, 2019
本文实例讲述了jQuery简单实现根据日期计算星期几的方法。分享给大家供大家参考,具体如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>3water.com jquery根据日期算周次</title> </head> <body> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script> $(function() { function ddd(types) { var text = ""; switch(types) { case 1: text = "星期一"; break; case 2: text = "星期二"; break; case 3: text = "星期三"; break; case 4: text = "星期四"; break; case 5: text = "星期五"; break; case 6: text = "星期六"; break; case 7: text = "星期日"; break; default: } return text; } var date = "2019-1-9"; var day = new Date(Date.parse(date)); var today = new Array('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'); var week = today[day.getDay()]; //最终结果为: console.log(week); }) </script> </body> </html>
这里使用在线HTML/CSS/JavaScript代码运行工具:http://tools.3water.com/code/HtmlJsRun测试上述代码,可得如下运行结果:
jQuery简单实现根据日期计算星期几的方法
- Author -
The_road_of_ordinary声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@