国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

JavaScript實現的日期控件具體代碼

2024-05-06 15:55:20
字體:
來源:轉載
供稿:網友
JavaScript實現的日期控件,它還會讀取當前的時間,有需要的朋友可以參考一下

復制代碼 代碼如下:


<html>
<head>
<style>
<!--
.wr{font-size: 12pt; line-height: 22px}
.wr1 {  FONT-SIZE: 12px; LINE-HEIGHT: 200%}
.wr2 {  FONT-SIZE: 14px; LINE-HEIGHT: 200%}
.wr3 {  FONT-SIZE: 12px}
.wr4 {  FONT-SIZE: 12px; LINE-HEIGHT: 150%}
// -->
</style>

<title>日期自動輸入控件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<style type="text/css">
.date-picker-wp {
display: none;
position: absolute;
background: #f1f1f1;
left: 40px;
top: 40px;
border-top: 4px solid #3879d9;
}
.date-picker-wp table {
border: 1px solid #ddd;
}
.date-picker-wp td {
background: #fafafa;
width: 22px;
height: 18px;
border: 1px solid #ccc;
font-size: 12px;
text-align: center;
}
.date-picker-wp td.noborder {
border: none;
background: none;
}
.date-picker-wp td a {
color: #1c93c4;
text-decoration: none;
}
.strong {font-weight: bold}
.hand {cursor: pointer; color: #3879d9}
</style>

<script type="text/javascript">
var DatePicker = function () {
var $ = function (i) 
{
   return document.getElementById(i)
},
addEvent = function (o, e, f) {o.addEventListener ? o.addEventListener(e, f, false) : o.attachEvent('on'+e, function(){f.call(o)})},
getPos = function (el) {
for (var pos = {x:0, y:0}; el; el = el.offsetParent) {
pos.x += el.offsetLeft;
pos.y += el.offsetTop;
}
return pos;
};
var init = function (n, config) {
window[n] = this;
Date.prototype._fd = function () {var d = new Date(this); d.setDate(1); return d.getDay()};
Date.prototype._fc = function () {var d1 = new Date(this), d2 = new Date(this); d1.setDate(1); d2.setDate(1); d2.setMonth(d2.getMonth()+1); return (d2-d1)/86400000;};
this.n = n;
this.config = config;
this.D = new Date;
this.el = $(config.inputId);
this.el.title = this.n+'DatePicker';
this.update();
this.bind();
};
init.prototype = {
update : function (y, m) {
var con = [], week = ['Su','Mo','Tu','We','Th','Fr','Sa'], D = this.D, _this = this;
fn = function (a, b) {return '<td colspan=3>'+year+'/'+month+'/'+date+'</td>'+fn("null, 1", ">")+fn("1, null", ">>")+'</tr>';
for (var i=0; i<con.length; i++) _html += (i==0 ? '<tr>' : i%7==0 ? '</tr><tr>' : '') + con[i] + (i == con.length-1 ? '</tr>' : '');
!!this.box ? this.box.innerHTML = _html : this.createBox(_html);
},
fillInput : function (y, m, d) {
var s = this.config.seprator || '/';
this.el.value = y + s + m + s + d;
this.box.style.display = 'none';
},
show : function () {
var s = this.box.style, is = this.mask.style;
s['left'] = is['left'] = getPos(this.el).x + 'px';
s['top'] = is['top'] = getPos(this.el).y + this.el.offsetHeight + 'px';
s['display'] = is['display'] = 'block';
is['width'] = this.box.offsetWidth - 2 + 'px';
is['height'] = this.box.offsetHeight - 2 + 'px';
},
hide : function () {
this.box.style.display = 'none';
this.mask.style.display = 'none';
},
bind : function () {
var _this = this;
addEvent(document, 'click', function (e) {
e = e || window.event;
var t = e.target || e.srcElement;
if (t.title != _this.n+'DatePicker') {_this.hide()} else {_this.show()}
});
},
createBox : function (html) {
var box = this.box = document.createElement('div'), mask = this.mask = document.createElement('iframe');
box.className = this.config.className || 'datepicker';
mask.src = 'javascript:false';
mask.frameBorder = 0;
box.style.cssText = 'position:absolute;display:none;z-index:9999';
mask.style.cssText = 'position:absolute;display:none;z-index:9998';
box.title = this.n+'DatePicker';
box.innerHTML = html;
document.body.appendChild(box);
document.body.appendChild(mask);
return box;
}
};
return init;
}();
onload = function () {
new DatePicker('_DatePicker_demo', {
inputId: 'date-input',
className: 'date-picker-wp',
seprator: '-'
});
}
</script>

<body bgcolor="#FFFFDB" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form >

  <table>

   <tr>
     <td> 生日:</td>
     <td>
         <input type="text">  <font color="RED">*</font>        
     </td>

   </tr>

  <tr> 
     <td><input type = "submit" value = "確定"/></td> 
     <td><input type = "reset" value = "重置"/></td> 
  </tr>
</table>

</form>
</body>
</html>

html頁面中的js執行順序:
1) 在head標簽內的最先執行
2) 在body標簽內的 執行
3) 當在 body標簽中 加了 onload  事件時 對應的 js 最后執行,也就是當頁面加載完在執行

注意:當在 body標簽中 加了 onload  事件時 在head標簽內,所引用外部的 js 不起作用,當換成 在body 內部或</html>之上引用外部js時可正常引用

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 景洪市| 肥东县| 南郑县| 辉县市| 壤塘县| 沙河市| 大英县| 朔州市| 郑州市| 巴青县| 兴和县| 满洲里市| 湘潭县| 淮滨县| 梨树县| 石泉县| 临湘市| 秦皇岛市| 沁源县| 赤水市| 屯门区| 金湖县| 景洪市| 独山县| 莫力| 武安市| 芦溪县| 淄博市| 称多县| 左贡县| 东丽区| 邢台市| 贵定县| 勐海县| 德安县| 威信县| 梨树县| 松潘县| 洛扎县| 日喀则市| 玛纳斯县|