//发一个格式化日期输入的小东西<br>
//最近开发的项目中,客户要求只输入月和日就出来日期的,默认年取当前年<br>
//就写了如下脚本,让大家见笑了。。。<br>
<script>
/*****writer:dxj********date:2008-3-10*****/
window.DateFormat = function(){var __DateFormat = this;this.$A = function(el){return (typeof el == 'object')?el:document.getElementsByTagName(el);};this.$G = function(){var O = this.$A("input") ,Ret = new Array() ,j = 0;if(typeof O.length != "undefined"){for(var i=0;i<O.length;i++){if(O[i].type == "text"){if(typeof O[i].DateFormat != "undefined"){Ret[j] = O[i];this.$R(O[i]);j++;}}}}return Ret;};this.$R = function(O){O.onpropertychange = function(){if(this.value != ""){__DateFormat.$C(this ,this.value ,this.DateFormat);}};};this.$C = function(O ,str ,style){var __str = str.replace(new RegExp(style ,"g") ,"");if(str.substr(str.length-1 ,1) != style){if(isNaN(__str*1)){O.value = str.substr(0 ,str.length-1);}}if(str.length > 10){O.value = str.substr(0 ,str.length-1);}var YY = new Date().getFullYear();var arr = O.value.split(style);if(arr.length == 2){var dt = new Date(YY ,arr[0] ,arr[1]);if(dt != "NaN"){O.value = YY + style + str;}}};this.$G();};
window.onload = function(){new window.DateFormat()};
</script>
只输入月加分割点加日试试,如:3-5 <br>
<input DateFormat="-" /> 以-为分割点<br>
<input DateFormat="." /> 以.为分割点<br>
<input DateFormat="/" /> 以/为分割点<br>