`
yexin218
  • 浏览: 958342 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

JavaScript日期控件

阅读更多

 

今天向大家介绍Swazz Javascript Calendar这个脚本日期控件。官方网址提供了使用方法和源代码下载. 官方网址
  演示效果图:

 
  现在简单介绍使用方法:
 

Step 1
Include the folllowing somewhere in the HTML of your page

< SCRIPT  SRC = "calendar.js" > < / SCRIPT > 

 

NB: Make sure "src" points to the correct location of the calendar.js file

Step 2
Find the input text box you would like the calendar to appear on. Modify it to include the following

< input  type = "text"  value = "dd/mm/yy"  onfocus = "this.select();lcs(this)"  onclick = "event.cancelBubble=true;this.select();lcs(this)" > 
 

 

英文很简单不需要翻译了吧。

但是你在测试的时候会发现,它只显示当前那个月以后的日历。不能显示这以前的日历,当然着也时候某些日期的使用,比如需要当天的时间,比如客房预订,肯定是当天以后的事情。但是如果是要填写生日的话,估计就需要几年前甚至几十年前的日子了。修改方法如下:

找到calendar.js中如下的代码:

// Calendar script

var now = new Date ;
var sccm= now. getMonth ( ) ;
var sccy= now. getFullYear ( ) ;
sccy = sccy- 2;//修改这里,几年前就减去几
var ccm= now. getMonth ( ) ;
var ccy= now. getFullYear ( ) ; 
 

 

正如代码中所描述的,假如你需要2两年前的当前月开始计算,那么就把sccy-2. 依此类推。很简单吧。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics