預設選中第二個按鈕(取消)的conform

來源:互聯網
上載者:User

test.htm
=====================================
<html>
<head>
<title> New Document </title>
<script language="javascript">
/*************************************************
功能:可以自己定製的confirm提示框,在IE6下測試通過

這個confirm用還可以做好多擴充,比如修改背景的顏色,修改那個顯示的圖片,修改按鈕的樣式,可以開啟象尋找那樣的非模態的視窗(需要IE5+),可以象定製網頁一樣隨便你修改

**************************************************/

/*
參數說明: strTitle confirm框的標題
   strMessage confirm框要顯示的訊息
   intType  confirm框的選中的類型1為選中YES,2為選中NO
   intWidth confirm框的寬度
   intHeight  confirm框的高度

*/
function myConfirm(strTitle,strMessage,intType,intWidth,intHeight)
{
 var strDialogFeatures = "status=no;center=yes;help=no;dialogWidth="+intWidth+";dialogHeight="+intHeight+";scroll=yes;resize=no";
 var args = new Array();
 args[args.length] = strTitle;
 args[args.length] = strMessage;
 args[args.length] = intType;
 var result = showModalDialog("myConfirm/myConfirm.htm",args,strDialogFeatures);
 return result;
}
function test()
{
 var myConfirmResult = myConfirm("這裡是標題","aaa",2,12,7)
 if(myConfirmResult)
  alert("您點了YES");
 else if(myConfirmResult == false)
  alert("您點了NO");
 else
  alert("您點了右上方的關閉");
}
</script>
</head>

<body>
<input type="button" value="點我試試" onclick="test()">
</html>

myConfirm/myConfirm.htm
=================================
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
<!--
var args = window.dialogArguments
try{
 document.title = args[0]; //設定標題
}catch(e)
{
//這裡屏蔽了錯誤,防止萬一調用的傳遞參數不足
}

//-->
</script>
<title></title>
<style type="text/css">
<!--
body {
 margin-left: 0px;
 margin-top: 0px;
 background-color: menu;
 overflow: hidden;
 overflow-x:hidden;
    overflow-y:hidden;
}
-->
</style>
<script language="javascript">
function init()
{
 var args = window.dialogArguments
 try{
  message.innerHTML = args[1]; //設定提示的資訊
  if(args[2] == 1)    //設定按鈕的選中狀態
   ok.focus(); 
  else
   cancel.focus();
 }catch(e)
 {
 //這裡屏蔽了錯誤,防止萬一調用的傳遞參數不足
 }
 ok.attachEvent("onclick",okClick); //設定YES按鈕的事件處理函數
 cancel.attachEvent("onclick",cancelClick);//設定NO按鈕的事件處理函數
}
function okClick()//YES按鈕的事件處理函數
{
  window.returnValue = true;
  window.close();
}
function cancelClick()//NO按鈕的事件處理函數
{
  window.returnValue = false
  window.close();
}
window.attachEvent("onload",init)
</script>
</head>

<body>
<table width="100%"  border="0" cellspacing="5">
  <tr>
    <td><div align="center">
      <img src="images/ico.gif" width="33" height="32"> </div></td>
    <td><div align="left" id="message"></div></td>
  </tr>
  <tr>
    <td>
      <div align="right">
        <input name="ok" type="button" id="ok" value="  確定  ">   
      </div></td>
    <td>
      <div align="left">
        <input name="cancel" type="button" id="cancel" value="  取消  ">
      </div></td>
  </tr>
</table>
</body>
</html>

用到的一個圖片如下:

有點麻煩,如果你不介意用VBscript的話還是用VBscript簡單

msgbox("aaa?",257)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.