重写window.confirm,页面刷新问题

knight2010 2009-07-04 01:39:12
将window.confirm用一个div代替后,对一个按钮执行一个回调函数,发现在页面上执行的被执行的函数参数始终为第一次的值,页面整体刷新后可以传入新值,要变化传入的参数值,就还需要刷新页面,有没有办法,每次不用刷新整个页面的
=======================confirm 封装后的代码===============================
function fn_confirm(msg){
if($('#temp_Over_Lay_confirm').length==0)
{
$('<div></div>')
.appendTo('body')
.attr('id','temp_Over_Lay_confirm')
.css({
'position':'absolute',
'left':'0px',
'top':'0px',
'background-color':'#000000',
'opacity':'0.2',
'filter':'alpha(opacity=20)',
'width':'100%',
'height':'100%',
'z-index':'12000010'
})
.append('<iframe src="about:blank" height="100%" width="100%"></iframe>')
.append('<div style="position:absolute;left:0px;top:0px;width:100%;height:100%;z-index:12000011;background-color:#000000;opacity:0.2;filter:alpha(opacity=20);"></div>');
}
else
{
$('#temp_Over_Lay_confirm').show();
}

var strInfo = msg||'';
if($('#temp_op_container_confirm').length==0)
{
$('<div></div>')
.appendTo('body')
.html(
' <style type="text/css">'+
' .ichTop{ background:url(./images/ch_ich_top_bg1.gif) no-repeat left top; }'+
' .ichTopInt{height:26px;line-height:26px;background:url(./images/ch_ich_top_bg2.gif) no-repeat right top;padding:0 10px;}'+
' h1.ichhead{ color:#FFF; line-height:26px;font-weight:normal; font-size:12px;background:url(./images/ch_ich_top_bg3.gif) repeat-x left top;}'+
' h1.ichhead span{ float:right; margin-top:5px; height:15px; width:15px; cursor:pointer; background:url(./images/ch_ridi_ico.gif) no-repeat left top }'+
' h1.ichhead span.sp01{ background:url(./images/ch_ico_rBhelp.gif) no-repeat left 1px; margin-right:10px; line-height:20px; height:20px; width:auto; padding-left:20px;margin-top:4px;}'+
' .ichText{ margin-left:0; background:#FFF; padding:1px; border:2px solid #3182CE; text-align:center}'+
' </style>'+
' <div style="padding-top:0px;border: solid 1px #81ADE8; padding:1px; background:#fff;">'+
' <div id="tempDragHeaderconfirm" class="ichTop" style="cursor:move;display:block;">'+
' <div class="ichTopInt">'+
' <h1 class="ichhead">'+
' <span id="spanColseconfirm" title="关闭"></span>'+
' <font id="__confirmTitle">确认提示</font>'+
' </h1>'+
' </div>'+
' </div>'+
' <div id="divinfoconfirm" style="margin:10px;word-wrap: break-word; word-break: break-all;">' + (strInfo+'').replace('\n','<br/>') +'</div>'+
' <div style="margin:auto;margin-top:10px;margin-bottom:8px;text-align:center;"><input type="image" alt="确定" id="makeconfirm" src="./images/ch_wrong_ico1.gif" style="border:0px;cursor:pointer;margin:auto;" />  <input type="image" alt="取消" id="btncloseconfirm" src="./images/ch_cancel.gif" style="border:0px;cursor:pointer;margin:auto;" /></div>'+
' </div>')
.attr({'id':'temp_op_container_confirm','class':'rightBox'})
.css({
'width':'300px',
'left':(($('body')[0].scrollWidth-400)/2+'px'),
'top':'200px',
'background-color':'#d0d0d0',
'position':'absolute',
'z-index':'12000012',
'display':''
});
$('#btncloseconfirm').click(function(){
$('#temp_op_container_confirm').hide();
$('#temp_Over_Lay_confirm').hide();
return true;
});
$('#makeconfirm').click(function(){
$('#temp_op_container_confirm').hide();
$('#temp_Over_Lay_confirm').hide();
//eval(fun_name);
return false;
});
$('#spanColseconfirm').mousedown(function(){
$('#temp_op_container_confirm').hide();
$('#temp_Over_Lay_confirm').hide();
goback(arguments[0]);
});
new dragMove(document.getElementById('tempDragHeaderconfirm'),document.getElementById('temp_op_container_confirm'),document.getElementById('temp_Over_Lay_confirm'));
} else {
$('#temp_op_container_confirm').show();
$('#divinfoconfirm').html((strInfo + '').replace('\n', '<br/>'));
$('#__confirmTitle').html('确认提示');
$('#temp_op_container_confirm').width(300);
}
$('#btncloseconfirm').focus();
return false;
}

//var makecofirm = window.confirm;
window.confirm = function() {
// if (arguments.length == 2 && arguments[1]) { fn_confirm(arguments[0],arguments[1]); return; }
// makecofirm(arguments[0]);
return fn_confirm(arguments[0]);
}
===========================confirm 封装完毕=======================================
===========================页面前端调用confirm====================================
function test(resid){
confirm("confirm重写","c_del_rec_sure("+resid+")");
}
function c_del_rec_sure(resid){
try{
windown.status(resid);
console.log("chirld="+resid);
}catch(e){
alert(e);
}

}
==========================页面调用完毕===========================================
chirld=0(传入参数resid=0)
chirld=0(传入参数resid=1)
.....
chirld=0(传入参数resid=3)
...全文
578 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lihan6415151528 2009-07-04
  • 打赏
  • 举报
回复
div里面可以放一个页面
之后刷新那个页面不就可以了
利用面向对象的方法,实现贪吃蛇。 1. 利用面向对象的思想实现——一个食物对象、一个蛇对象、一个游戏总控对象。 2. 在使用××.prototype= {}重写原型对象的时候,一定要加上一句constructor:该对象。不然会造成实例化出来的实例的constructor为object。 3. 在underscore中,使用_.random(a,b)即可获得a-b中的一个随机数。 4. 在求食物的随机位置的时候,用到了panel.clientHeight/this.height - 1) * this.height。 原理是使用盒子的高度/小球的高度,可以算得最多放多少个小球。因为要控制小球不能超过边界,所以总数量要减去1,数量×高度即为随机位置的最大值。 5. 在蛇对象中,用body数组存放蛇身体每一个部分对象。蛇的绘制过程就是遍历body,在面板上绘制。 6. 蛇的移动分为两部分。 ① 蛇节移动到前一个蛇节的位置。直到蛇头后一个蛇节移动到蛇头的位置。 ② 根据direction判断蛇头如何移动。 注意:在游戏绘制的过程中,界面的每一次绘制都要**删除**之前的绘制,不然会叠加到一起。 7. 在蛇的闭包中建一个局部数组,存储蛇对象,可以更加方便的删除操作。 8. 只有在原型对象中的方法和属性,外界是可以调用的。 9. 蛇的移动(动画)必然需要定时器协助。定时器的时间,即象征着刷新速度,也就是难度。 10. this所在的函数在哪一个对象中,this就指向谁。单独写一个函数的时候,如果调用之前对象的this,需要备份指针(将对象的this赋值给另一个变量)。 11. JavaScript原生的键盘按下事件(keydown) 中,事件有一个keyCode属性,其值代表按下的键。其中:37—left、38—top、39—right、40—bottom。 12. 边界控制。通过判断蛇头与最大X和Y的关系,判断是否碰到边界。 13. confirm()方法用于显示一个带有指定消息和确认及取消按钮的对话框。 14. window.location.reload(); 重新加载当前文档 15. window.close() 方法用于关闭浏览器窗口。 16. 与食物的碰撞检测:如果蛇头和食物坐标重叠,将蛇尾添加到body中。并重新绘制一个食物点,将之前的食物删掉。

52,782

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧