懒得写,自己从里边找吧
<html>
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript" src="test.js" type="text/jscript"></script></head>
<BODY >
<script>
alert(k);
k="iloveyou too";
alert(k);
function look(){ 
if(event.ctrlKey) 
alert("禁止按ctrl键!"); //可以换成ALT CTRL

document.onkeydown=look;
</script><input type="text" name="txt" maxlength="16" onfocus="init(this)" onkeyup="inputTM(this)" onkeypress="regInputTM()" onkeydown="checkpress(this,event.keyCode)">
<input type="text" name="txt" maxlength="16" onfocus="init(this)" onkeyup="inputTM(this)" onkeypress="regInputTM()" onkeydown="checkpress(this,event.keyCode)">
<input type="text" name="txt" maxlength="16" onfocus="init(this)" onkeyup="inputTM(this)" onkeypress="regInputTM()" onkeydown="checkpress(this,event.keyCode)">
<input type="text" name="txt" maxlength="16" onfocus="init(this)" onkeyup="inputTM(this)" onkeypress="regInputTM()" onkeydown="checkpress(this,event.keyCode)">
<input type="text" name="txt" maxlength="16" onfocus="init(this)">
<script language="javascript">function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart("character",e.value.length);
r.collapse(true);
r.select();
}
    var pubyear,pubmonth,pubday,pubhour,pubmini;
    var Date1=new Date();
    pubyear=Date1.getYear();
    pubmonth=(Date1.getMonth()+1);
    pubday=Date1.getDate();
    pubhour=Date1.getHours();
    pubmini=Date1.getMinutes();    pubmonth=pubmonth<10?("0"+pubmonth):pubmonth;
    pubday=pubday<10?("0"+pubday):pubday;
    pubhour=pubhour<10?("0"+pubhour):pubhour;
    if(pubmini>=55) pubmini="55";
    else{
      if((pubmini%5)<3) pubmini=pubmini-pubmini%5;
      else pubmini=pubmini-pubmini%5+5;
    }
    pubmini=pubmini<10?("0"+pubmini):pubmini;
    pubCurDate=pubyear+"-"+pubmonth+"-"+pubday;
    pubCurTime=pubCurDate+" "+pubhour+":"+pubmini;function init(src){
src.value=pubCurTime;
src.select();}
function checkpress(src,e){
if(event.keyCode==13){
event.keyCode=9;
}
else return ;
var strTime=pubCurDate+" "+pubhour+":"+"00"
var val=src.value;
var len=val.length;
if(len<16){
val=val+strTime.substring(len,16);
src.value=val;
}}function inputTM(src){
var reg=/^\d{1,4}([-\/](\d{1,1}(\d{1,1}([-\/](\d{1,1}(\d{1,1}([ \/](\d{1,1}(\d{1,1}([:\/](\d{1,1}(\d{1,1})?)?)?)?)?)?)?)?)?)?)?)?$/ ;
if(event.keyCode==8 || event.keyCode==46) return true
var srcElem    = src
var oSel    = document.selection.createRange()
var srcRange    = srcElem.createTextRange()
oSel.setEndPoint("StartToStart", srcRange)
var strSplit=""
switch((src.value).length)
{
case 4:
case 7:
strSplit="-";
break;
case 10:
strSplit=" ";
break;
case 13:
strSplit=":";
break;
default:
break;
}
if(strSplit!="")
{
var num = src.value+strSplit
if( reg.test(num))
src.value=src.value+strSplit
}}function regInputTM()
{
var reg= /^\d{1,4}([-\/](\d{1,1}(\d{1,1}([-\/](\d{1,1}(\d{1,1}([ \/](\d{1,1}(\d{1,1}([:\/](\d{1,1}(\d{1,1})?)?)?)?)?)?)?)?)?)?)?)?$/ ;
if(event.keyCode==8 || event.keyCode==46) return true
var srcElem    = event.srcElement
var oSel    = document.selection.createRange()
var srcRange    = srcElem.createTextRange()
oSel.execCommand( "Cut")
oSel.setEndPoint("StartToStart", srcRange)
var num = oSel.text + String.fromCharCode(event.keyCode) + srcRange.text.substr(oSel.text.length)
event.returnValue = reg.test(num)
}</script>
</body>
</html>

解决方案 »

  1.   

    <script>
    function  aa(){
    var a=document.form1.text1.value
    var i
    var j=document.form1.text1.value.lenght
    for (i=0,i>=j,i++){
       if(i%2==0){
         if(i%1==0){
            if(a.substr(3,4)=="-"){
               if(a.substr(6,7)=="-"){
                  if(a.substr(9,10)==" "){
                     if(a.substr(12,13)==":"){
                     document.alert("是日期型")
                                             }
                     else{
                     document.alert("否日期型")
                         }
                           }
                       }
                    }
                }
           }
    }
    </script>
    <body>
    <form action="" name="from1">
    <input type="text" name="text1">
    <input type="submit" name="submit1" onclick="aa()">
    </form>
    </body>
      

  2.   

    上面的符号打错拉
    <script>
    function  aa(){
    var a=document.form1.text1.value
    var i
    var j=document.form1.text1.value.lenght
    for (i=0,i=j,i++){                           〈〈-----------******************
       if(i%2==0){
         if(i%1==0){
            if(a.substr(3,4)=="-"){
               if(a.substr(6,7)=="-"){
                  if(a.substr(9,10)==" "){
                     if(a.substr(12,13)==":"){
                     document.alert("是日期型")
                                             }
                     else{
                     document.alert("否日期型")
                         }
                           }
                       }
                    }
                }
           }
    }
    </script>
    <body>
    <form action="" name="from1">
    <input type="text" name="text1">
    <input type="submit" name="submit1" onclick="aa()">
    </form>
    </body>
      

  3.   

    <script>
    alert((/^\d{4}\-\d{2}\-\d{2}\s\d{2}\:\d{2}$/).test('2004-10-08 25:99:59'));
    alert((/^\d{4}\-\d{2}\-\d{2}\s\d{2}\:\d{2}$/).test('2004-10-08'));
    alert((/^\d{4}\-\d{2}\-\d{2}\s\d{2}\:\d{2}$/).test('2004-10-08 25:99'));
    </script>这个就可以了