『 更新时间:2008-06-21 』『 字体:大 中 小 』『 作者:hanshr | 来源:蓝色理想 』
以日期格式显示时间的效果
<!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> New Document </TITLE>
<style>
fieldset{ width:300px; padding:20px;}
</style>
<script type="text/javascript">
var data_help = function(inp, format){
this.inp = document.getElementById(inp);
this.format = format;
var div = document.createElement('div');
div.setAttribute('style', 'height:21px; font-size:12px; line-height:21px; background:#fffff6; color:#f33; border:1px solid #ccc; border-top:0; text-indent:3px; position:absolute; visibility:hidden');
div.style.cssText = 'height:21px; line-height:21px;font-size:12px; background:#fffff6; color:#f33; border:1px solid #ccc; border-top:0; text-indent:3px; position:absolute; visibility:hidden'; 字串5
div.innerHTML = this.format;
this.div = div;
document.body.appendChild(div);
this.load();
var oThis = this;
this.inp.onfocus = function(){
oThis.inp_v.call(oThis);
}
this.inp.onblur = function(){
oThis.inp_h.call(oThis);
}
this.inp.onkeyup = function(){
oThis.inp_chk.call(oThis);
}
}
data_help.prototype={
load: function(){
var inp = this.inp;
var inpW = inp.offsetWidth, inpH = inp.offsetHeight;
var left = 0, top = 0;
while(inp != null){
left += inp.offsetLeft;
top += inp.offsetTop;
inp = inp.offsetParent;
}
this.div.style.height = '21px';
this.div.style.width = inpW-2 + 'px';
this.div.style.left = left + 'px';
this.div.style.top = inpH+top + 'px';
},
inp_v: function(){
this.div.style.visibility = 'visible';
},
inp_h: function(){ 字串9
this.div.style.visibility = 'hidden';
},
inp_chk: function(){
var p = this.inp.value.replace(/\s/g,'');
var w = this.format;
var n=0;
for(var i=0; i<p.length; i++){
if(/[^a-zA-Z]/.test(w.charAt(i))){
if(p.charAt(i)!=w.charAt(i)){
break;
}
}
n++;
}
this.div.innerHTML= '<span style="font-weight:bold; color:green">'+w.slice(0,n)+'</span>'+w.slice(n,w.length);
}
}
window.onload = function(){
new data_help('birthday', 'yyyy/mm/dd');
new data_help('birthday2', 'yyyy-mm-dd');
}
</script>
</HEAD>
<body>
<div>
日期1:<input type="text" id="birthday" /><br/><br /><br />
日期2:<input type="text" id="birthday2" /><br/><br /><br />
</div>
</body>
</html> 字串2
上一篇:文字间歇滚动效果的js代码
下一篇:实现网页可拖动的布局方法
Power by DedeCms CopyRight 2006-2008 www.68start.com All Rights Reserved 起点设计资源网
本站部分文章来自于网络,如有侵犯您的权益请与我们联系,本站将第一时间纠正