confirm用法和例子

一般用于弹出对话框(确定/否)
确定:就执行其嵌套的内容;否:则反之

<script language="javascript">   
//验证时间格式  YYYY-MM-DD/YYYY,MM,DD   
function isDate(date){   
    var regu = "^[0-9]{4}-([0-1]?)[0-9]{1}-([0-3]?)[0-9]{1}$";   
    var re   = new RegExp(regu);   
    if (date.search(re) != -1)   
        return true;   
    else  
        return false;   
}    
function sureButton(){   
   if(!confirm('真的要删除吗?删除后将无法恢复!')){   
       return;   
   }   
   //验证时间格式  YYYY-MM-DD   
  
       var startDate=document.getElementById("startDate").value;   
       var endDate=document.getElementById("endDate").value;    
       if(!isDate(startDate)){   
                   
             alert(startDate+"请输入正确的开始日期格式!如:(YYYY-MM-DD)2008-01-01");   
             return document.getElementById("startDate").focus();   
       }   
       if(!isDate(endDate)){   
             alert("请输入正确的结束日期格式!如:(YYYY-MM-DD)2008-01-01");   
             return document.getElementById("endDate").focus();   
       }   
         if(startDate==""){   
    alert("请输入开始日期");   
    return document.getElementById("startDate").focus();   
   }   
   if(endDate==""){   
    alert("请输入结束日期");   
    return document.getElementById("endDate").focus();   
   }    
   startDate=startDate.replace(new RegExp('-', 'g'),'/');   
   alert(startDate);   
   endDate=endDate.replace(new RegExp('-', 'g'),'/');   
   var startTime=new Date(startDate).getTime();   
   alert(new Date(startDate).getTime());   
   var endTime=new Date(endDate).getTime();   
   if((endTime-startTime)<0){   
    alert("结束日期必须大于开始日期");   
        return document.getElementById("endDate").focus();   
   }      
      
      
}   
</script>  


<html>    
<head>   
<meta http-equiv="Content-Language" content="zh-cn">   
<meta name="generator" content="Bluefish 1.0.7">   
<meta name="ProgId" content="FrontPage.Editor.Document">   
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">   
<title></title>   
<style type="text/css">   
  table{color: #000000; font-family: 宋体; font-size: 12px; height:12 }   
  t1{color:#008000;align:center}   
</style>   
</head>   
  
<body topmargin="0" leftmargin="0">   
  
<div align="left">   
  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="461" height="8" id="AutoNumber1" background="images/kabg.gif">   
    
    <tr>   
      <td  colspan="3">   
      <table cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="17">   
          <tr>   
       <td width="19%" height="25" align="center" style="border:1px solid #000080;"><font color="#008000">开始日期</font></td>   
       <td width="31%" style="border:1px solid #000080;">    
              <input name="startDate" type="text" id="startDate" size="15"></td>   
       <td width="22%" align="center" style="border:1px solid #000080;"><font color="#008000">结束日期</font></td>   
       <td width="28%" style="border:1px solid #000080;">    
              <input name="endDate" type="text" id="endDate" size="15"></td>   
       </tr>   
       </table>   
       </td>   
    </tr>   
  
    <tr>   
      <td height="28" align="center" style="border:1px solid #000080; " colspan="3">   
      <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3" height="17">   
        <tr>   
          <td width="14%" align="center" height="25">   
      <font color="#008000">当前状态</font></td>   
          <td width="18%" align="center" height="25">   
      <select size="1" name="display">   
      <option value="0">无效</option>   
      <option value="1">等待</option>   
      <option value="2" selected>显示中</option>   
      </select></td>   
          <td width="15%" align="center" height="25" style="border-left: 1px solid #000080; border-right-width: 1; border-top-width: 1; border-bottom-width: 1">   
          <font color="#008000">Logo行宽</font></td>   
          <td width="10%" align="center" height="25">   
      <select size="1" name="colValue">   
      <option>1</option>   
      <option>2</option>   
      <option>3</option>   
      <option>4</option>   
      <option>5</option>   
      <option>6</option>   
      </select></td>   
       <td width="12%" align="center" style="border-left: 1px solid #000080; border-right-width: 1; border-top-width: 1; border-bottom-width: 1"><font color="#008000">显示顺序</font></td>   
       <td width="5%" >    
              <input name="displayOrder" type="text" id="displayOrder" size="3" value="1">   
     </td>   
          <td width="43%" align="center" height="25" style="border-left-style: solid; border-left-width: 1; border-right-width: 1; border-top-width: 1; border-bottom-width: 1">   
      <input onclick="cancelButton()" type="reset" value="关闭" name="B2" style="border-style: outset; border-width: 1; color:#0000FF">    
      <input onclick="sureButton()" type="submit" value="确定" name="B1" style="border-style: outset; border-width: 1; color:#0000FF"></td>   
        </tr>   
      </table>   
      </td>   
    </tr>   
    <tr>   
      <td height="20" colspan="3" align="center" style="border:1px solid #000080; ">   
      <marquee behavior="slide" style="color: #808080">::日期格式为年-月-日,直接填入图片和点击路径全名时应仔细查对是否正确::</marquee></td>   
    </tr>   
  </table>   
</div>   
  
</body>   
  
</html> 

你可能感兴趣的:(html)