相信有人会在页面中中选择日期时,需要知道选择日期的农历!如果是Java的话,在后台一下子就可以给转换掉,但是页面上,通过JavaScript来转换的话,不知道大伙儿有没有好的想法呢?刚好,前一段时间来,朋友问了这么一个问题,然后就写了一个demo给她,还行吧!希望能帮到有需要的各位,好啦,直接上代码,不想闲扯:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>mydate.jsp</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <link rel="stylesheet" type="text/css" href="My97DatePicker/skin/WdatePicker.css"> <style type="text/css"> body { font-family: 微软雅黑; font-size: 14px; } </style> <script type="text/javascript" src="My97DatePicker/calendar-converter.js"></script> <script type="text/javascript" src="My97DatePicker/WdatePicker.js"></script> <script type="text/javascript" src="jQuery/jquery-1.6.js"></script> </head> <body> <div id="calendar"> <div id="showCalendar"></div> <div><span id="showSolarCalendar"></span>[<span id="showLunarCalendar"></span>]</div> </div> </body> <script type="text/javascript"> function getLunarCalendar(date){ var cc = new CalendarConverter; var result = cc.solar2lunar(date); return result.cYear + "(" + result.lunarYear + ")年" + (result.isLeap?"闰":"") + result.lunarMonth + "月" + result.lunarDay + " " + result.lunarFestival + " 星期" + result.week; } var nowDate = new Date(); document.getElementById('showSolarCalendar').innerHTML = nowDate.getFullYear() + "-" + (nowDate.getMonth() + 1) + "-" + nowDate.getDate(); document.getElementById('showLunarCalendar').innerHTML = getLunarCalendar(nowDate); WdatePicker({ eCont:'showCalendar', onpicked:function(dp){ document.getElementById('showSolarCalendar').innerHTML = dp.cal.getDateStr(); document.getElementById('showLunarCalendar').innerHTML = getLunarCalendar(new Date(dp.cal.getDateStr())); } }); </script> </html>
查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/
代码就已经贴上了,关键这里有一个js:calendar-converter.js,主要是用来公历转换农历的!附上该资源下载地址:http://download.csdn.net/download/luo201227/7616913
最后给大伙儿贴上几张效果图:
1:
2:
3:
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索innerhtml
, wdatepicker
, document
, result
, getelementbyid
, 农历
, 公历和农历转换
, 公历农历转换
js获取农历日期
农历转换公历、农历转换公历对照表、万年历公历农历转换、excel农历转换公历、公历农历转换器,以便于您获取更多的相关知识。