默认选中第二个按钮(取消)的conform

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 awaysrain 的 blog

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)

本文关键:confirm 取消 选中
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top