怎么实现confirm()函数默认焦点在取消按钮上,网上找的都是好多年前没用的
function window.confirm(str)
{
execScript("n = msgbox('"+ str +"', 257, '自定的 confirm')", "javascript");
return(n == 1);
}
现在有没有好的方法,还在学习JS过程中,自己做不来
应该怎么重写confirm()函数
大侠们帮个忙
function window.confirm(str)
{
execScript("n = msgbox('"+ str +"', 257, '自定的 confirm')", "javascript");
return(n == 1);
}
现在有没有好的方法,还在学习JS过程中,自己做不来
应该怎么重写confirm()函数
大侠们帮个忙
你可以做一个遮罩+弹出层模拟confirm效果就能设置焦点了
msgbox ("msg", 257 )
你没用过弹出层?自己做弹出层,样式是最灵活的,完全自定义,你做成和comfire一模一样都没问题
confirm好像 没有其它参数了,用 window.showdialog() 模拟 试试
其它你不一定要纠结这默认按钮上,这关系不大
你没用过弹出层?自己做弹出层,样式是最灵活的,完全自定义,你做成和comfire一模一样都没问题我试试看,多谢
confirm好像 没有其它参数了,用 window.showdialog() 模拟 试试
其它你不一定要纠结这默认按钮上,这关系不大恩,但是需求上要求默认焦点在取消按钮上,我试试看这个函数
你没用过弹出层?自己做弹出层,样式是最灵活的,完全自定义,你做成和comfire一模一样都没问题
正解,
++1
本JS代码用于创建一个自定义的确认窗口,
具体功能包括:自定义窗口标题,自定义窗口内容,是否显示取消按钮,焦点位置设定
*/
function get_width(){
return (document.body.clientWidth+document.body.scrollLeft);
}
function get_height(){
return (document.body.clientHeight+document.body.scrollTop);
}
function get_left(w){
var bw=document.body.clientWidth;
var bh=document.body.clientHeight;
w=parseFloat(w);
return (bw/2-w/2+document.body.scrollLeft);
}
function get_top(h){
var bw=document.body.clientWidth;
var bh=document.body.clientHeight;
h=parseFloat(h);
return (bh/2-h/2+document.body.scrollTop);
}
function create_mask(){//创建遮罩层
var mask=document.createElement("div");
mask.id="mask";
mask.style.position="absolute";
mask.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=4,opacity=25)";
mask.style.opacity=0.4;//Mozilla设置不透明度
mask.style.background="black";
mask.style.top="0px";
mask.style.left="0px";
mask.style.width=get_width();
mask.style.height=get_height();
mask.style.zIndex=1000;
document.body.appendChild(mask);
}
function create_msgbox(w,h,t){//创建弹出对话框
var box=document.createElement("div") ;
box.id="msgbox";
box.style.position="absolute";
box.style.width=w;
box.style.height=h;
box.style.overflow="visible";
box.innerHTML=t;
box.style.zIndex=1001;
document.body.appendChild(box);
re_pos();
}
function re_mask(){
/*
更改遮罩层的大小,确保在滚动以及窗口大小改变时还可以覆盖所有的内容
*/
var mask=document.getElementById("mask") ;
if(null==mask)return;
mask.style.width=get_width()+"px";
mask.style.height=get_height()+"px";
}
function re_pos(){
/*
更改弹出对话框层的位置,确保在滚动以及窗口大小改变时一直保持在网页的最中间
*/
var box=document.getElementById("msgbox");
if(null!=box){
var w=box.style.width;
var h=box.style.height;
box.style.left=get_left(w)+"px";
box.style.top=get_top(h)+"px";
}
}
function remove(){
/*
清楚遮罩层以及弹出的对话框
*/
var mask=document.getElementById("mask");
var msgbox=document.getElementById("msgbox");
if(null==mask&&null==msgbox)return;
document.body.removeChild(mask);
document.body.removeChild(msgbox);
}
function return0(){
return 0;
}
function return1(){
return 1;
}
function msgbox(){
/*
参数列表说明:
title :弹出对话框的标题,标题内容最好在25个字符以内,否则会导致显示图片的异常
text :弹出框的内容,可以用html代码
func :弹出对话框点击确认后执行的函数,需要写全函数的引用
cancel:弹出对话框是否显示取消按钮,为空不显示,为1显示
focus :弹出对话框焦点的位置,0焦点在确认按钮,1在取消按钮,为空默认在确认按钮上
*/
create_mask();
var title = "确定要删除?";
var text = "<font color='red'>删除后将无法恢复!</font>";
var temp="<table width=\"355\" height=\"127\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"font:14px Verdana, Geneva, Arial, Helvetica, sans-serif\">";
temp+="<tr><td background=\"msgbox/alert_01.gif\" width=\"355\" height=\"22\" style=\"padding-left:8px;padding-top:2px;font-weight: bold;color:white;\">"+title+"</td></tr>";
temp+="<tr><td background=\"msgbox/alert_02.gif\" width=\"355\" height=\"75\" style=\"padding-left:6px;padding-right:2px;padding-bottom:10px;\"> <img src=\"msgbox/alert_.gif\"> "+text+"</td>";
temp+="</tr><tr><td width=\"355\" height=\"22\" align=\"center\" background=\"msgbox/alert_03.gif\"><input name=\"msgconfirmb\" type=\"button\" id=\"msgconfirmb\" value=\"确定\" onclick=\"remove();"+return1+";\">";
temp+=" <input name=\"msgcancelb\" type=\"button\" id=\"msgcancelb\" value=\"取消\" onclick=\"remove();"+return0+";\"></td>";}
temp+="</tr><tr><td background=\"msgbox/alert_04.gif\" width=\"355\" height=\"8\"></td></tr></table>";
create_msgbox(400,200,temp);
document.getElementById("msgcancelb").focus();
}
function re_show(){
/*
重新显示遮罩层以及弹出窗口元素
*/
re_pos();
re_mask();
}
function load_func(){
/*
加载函数,覆盖window的onresize和onscroll函数
*/
window.onresize=re_show;
window.onscroll=re_show;
}