麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 編程 > JavaScript > 正文

jQuery之日期選擇器的深入解析

2019-11-20 22:38:19
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

1:默認(rèn)情況下,日期輸入文本框獲得頁(yè)面焦點(diǎn)的時(shí)候,日期選擇器組件會(huì)在一個(gè)覆蓋層中打開日歷選擇面板,當(dāng)日期輸入文本框失去焦點(diǎn)或者選擇一個(gè)日期的時(shí)候,將自動(dòng)關(guān)閉該日歷選擇面板
$(selector).datepicker([options]);
簡(jiǎn)單實(shí)例:

復(fù)制代碼 代碼如下:

<!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=gb2312" />
<title>DatePicker Local</title>
<link rel="stylesheet" type="text/css" href="themes/ui-lightness/jquery.ui.all.css"/>
<script type="text/javascript" src="JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="JS/jquery.ui.core.js"></script>
<script type="text/javascript" src="JS/jquery.ui.datepicker.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $("#inputDate").datepicker({
  /* 區(qū)域化周名為中文 */
  dayNamesMin : ["日", "一", "二", "三", "四", "五", "六"], 
  /* 每周從周一開始 */
  firstDay : 1,
  /* 區(qū)域化月名為中文習(xí)慣 */
  monthNames : ["1月", "2月", "3月", "4月", "5月", "6月",
     "7月", "8月", "9月", "10月", "11月", "12月"],
  /* 月份顯示在年后面 */
  showMonthAfterYear : true,
  /* 年份后綴字符 */
  yearSuffix : "年",
  /* 格式化中文日期
  (因?yàn)樵路葜幸呀?jīng)包含“月”字,所以這里省略) */
  dateFormat : "yy年MMdd日"  
 }); 
});
</script>
<style>
*{ font-size:12px; }
</style>
</head>
<body>
請(qǐng)輸入一個(gè)日期:
<input type="text" id="inputDate" />
</body>
</html>

效果圖:
 

2:指定彈出日期選擇器的圖片按鈕
需要添加響應(yīng)的資源文件:
復(fù)制代碼 代碼如下:

         $(document).ready(function() {
                  $("#datepicker").datepicker({
                               showOn: "button",
                               buttonImage: "Images/calendar.gif",
                               buttonImageOnly: true
                 });
          }); 

復(fù)制代碼 代碼如下:

<!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=gb2312" />
<title>DatePickerIcon</title>
<link rel="stylesheet" type="text/css" href="themes/ui-lightness/jquery.ui.all.css"/>
<script type="text/javascript" src="JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="JS/jquery.ui.core.js"></script>
<script type="text/javascript" src="JS/jquery.ui.datepicker.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $( "#datepicker" ).datepicker({
  showOn: "button",
  buttonImage: "Images/calendar.gif",
  buttonImageOnly: true
 });
});
</script>
<style>
*{ font-size:12px; }
body{ padding : 30px; }
#datepicker{ margin:0; height:13px; }
</style>
</head>
<body>
<div>請(qǐng)選擇一個(gè)日期:<input type="text" id="datepicker"></div>
</body>
</html>

效果圖:
  

3:顯示帶年、月份下拉列表和按鈕面板的日期選擇器
復(fù)制代碼 代碼如下:

<!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=gb2312" />
<title>DatePicker Local</title>
<link rel="stylesheet" type="text/css" href="themes/ui-lightness/jquery.ui.all.css"/>
<script type="text/javascript" src="JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="JS/jquery.ui.core.js"></script>
<script type="text/javascript" src="JS/jquery.ui.datepicker.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $("#inputDate").datepicker({
  changeMonth: true,  //可以選擇月份
  changeYear: true,   //可以選擇年份
  showButtonPanel: true,  //顯示按鈕面板
  currentText: '今天',  //當(dāng)前日期按鈕上顯示的文字
  closeText: '關(guān)閉',    //關(guān)閉按鈕上顯示的文本
  yearRange: 'c-60:c+20'

 }); 
});
</script>
<style>
*{ font-size:12px; }
</style>
</head>
<body>
請(qǐng)輸入一個(gè)日期:
<input type="text" id="inputDate" />
</body>
</html>

效果圖:
  
4:同時(shí)顯示多個(gè)月份的日期選擇器
復(fù)制代碼 代碼如下:

<!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=gb2312" />
<title>DatePickerButton</title>
<link rel="stylesheet" type="text/css" href="themes/ui-lightness/jquery.ui.all.css"/>
<script type="text/javascript" src="JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="JS/jquery.ui.core.js"></script>
<script type="text/javascript" src="JS/jquery.ui.datepicker.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $( "#datepicker" ).datepicker({
  numberOfMonths : 3,  //顯示月份的個(gè)數(shù)
  showCurrentAtPos : 1,  //當(dāng)前月份在第二個(gè)位置
  stepMonths : 3  //翻頁(yè)時(shí)一次跳過(guò)三個(gè)月份
 });
});
</script>
<style>
*{ font-size:11px; }
#datepicker{ margin:0; height:13px; }
</style>
</head>
<body>
請(qǐng)選擇一個(gè)日期:<input type="text" id="datepicker">
</body>
</html>

效果圖:
  

5:日期選擇器的一些方法
dialog, isDisabled, hide, show, refresh, getDate, setDate
復(fù)制代碼 代碼如下:

<!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=gb2312" />
<title>DatePicker Dialog</title>
<link rel="stylesheet" type="text/css" href="themes/ui-lightness/jquery.ui.all.css"/>
<script type="text/javascript" src="JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="JS/jquery.ui.core.js"></script>
<script type="text/javascript" src="JS/jquery.ui.datepicker.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $("#inputDate").datepicker(); 
 $("#showDialog").click(function(){
  $("#inputDate").datepicker("dialog","",function(dateText, inst){
   $("#inputDate").val(dateText);
  });
 });
});
</script>
<style>
*{ font-size:12px; }
</style>
</head>
<body>
請(qǐng)輸入一個(gè)日期:
<input type="text" id="inputDate" />
<button id="showDialog">Show</button>
</body>
</html>

效果圖:
  

6:日期選擇器的一些事件
6.1 beforeShow事件:顯示日期選擇器之前觸發(fā)該事件。
6.2 beforeShowDay事件:日期選擇器上每一天選擇之前都將觸發(fā)該事件  function(date) {}
6.3 onChangeMonthYear: 當(dāng)日期選擇器選定新的年份或者月份時(shí)觸發(fā)該事件function(year, month, inst);
6.4 onClose事件:當(dāng)關(guān)閉日期選擇器控件的時(shí)候觸發(fā)此事件。function(dataText, inst) {}
6.5 onSelect事件:當(dāng)日期選擇器選中一個(gè)日期時(shí)觸發(fā)該事件。function(dataText, inst) {}   //dataText為所選的日期的字符串,inst為日期選擇器實(shí)例
復(fù)制代碼 代碼如下:

<!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=gb2312" />
<title>DatePicker Dialog</title>
<link rel="stylesheet" type="text/css" href="themes/ui-lightness/jquery.ui.all.css"/>
<script type="text/javascript" src="JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="JS/jquery.ui.core.js"></script>
<script type="text/javascript" src="JS/jquery.ui.datepicker.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 /* 有日志的日期集合 */
 var hasLog=[{ month:10,  day:1 },
    { month:10, day:5 },
    { month:10, day:20 }];

 function hasToday(date){
  /* 測(cè)試當(dāng)前日期是否在集合中存在有相同項(xiàng) */
  for(var i in hasLog){
   /* 因?yàn)閖s中的Date類型的月份取值范圍是0-11,
    所以這里調(diào)用getDate()以后要加1才是當(dāng)前月份 */
   if(hasLog[i].month == (date.getMonth()+1) &&
    hasLog[i].day == date.getDate()){
    return true;
   }
  }
  return false
 }

 $("#datepicker").datepicker({
  beforeShowDay : function(date){
   /* 在顯示日期之前,
    測(cè)試如果當(dāng)前日期在集合中存在,
    則為當(dāng)前日期添加一個(gè)class */
   var dat = new Date(date);
   var css ="" ;
   if(hasToday(dat)){
    css="light_day";
   }
   return [true, css];
  },
  onSelect : function(dateText,inst){
   /* 在選中日期之后,
    測(cè)試如果當(dāng)前日期在集合中存在,
    則向頁(yè)面打印相應(yīng)的提示信息 */
   var dat = new Date(dateText);
   if(hasToday(dat)){
    var msg="得到了日期:" + dateText +
     ",我們可以在這里查詢當(dāng)前日期的日志列表";
    $("#logList").text(msg);
   }
  }
 });
});
</script>
<style>
body{ padding:30px; }
*{ font-size:12px; }
#logList{ margin:10px 0; padding:8px; }
.light_day .ui-state-default{ background:#fdc; }
.light_day .ui-state-default:hover,
.light_day .ui-state-default:active{ background:#fed; }
</style>
</head>
<body>
<div id="datepicker"></div>
<div id="logList"></div>
</body>
</html>

效果圖:
  

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 欧美一级理论 | 成人福利网 | 91九色福利 | 蜜桃一本色道久久综合亚洲精品冫 | 88xx成人永久免费观看 | 在线免费观看欧美 | 在线亚洲观看 | 欧美精品99 | 曰韩毛片 | av之家在线观看 | lutube成人福利在线观看 | 无遮挡一级毛片视频 | 精品一区二区久久久久 | 男人的天堂色偷偷 | 9797色 | 欧洲色阁中文字幕 | 久久91久久久久麻豆精品 | 青草视频在线观看视频 | 久久精品观看 | 一区二区三区日韩在线观看 | 最新欧美精品一区二区三区 | 久久午夜神器 | 91 在线视频观看 | 欧美色视 | 成人羞羞在线观看网站 | 日韩精品中文字幕一区二区三区 | 日本xxxx视频 | 国产一及毛片 | 亚洲国产综合在线观看 | 操操插插 | 在线成人一区二区 | 欧美高清第一页 | 羞羞羞网站 | 成人男女啪啪免费观看网站四虎 | 日本黄色免费播放 | 中文字幕在线播放不卡 | 一级黄色在线免费观看 | 欧美性猛交xxx乱大交3蜜桃 | 一本色道久久综合亚洲精品图片 | 久久综合久久精品 | 欧美日韩免费在线观看视频 |