读书人

jquery重写兑现confirm功能

发布时间: 2012-08-29 08:40:14 作者: rapoo

jquery重写实现confirm功能
写个函数实现confirm,要改样式,改函数名为Confirm,下面是我写的函数,但是不行,大家帮忙看看是什么问题
function Confirm(msg)
{
var alertFram = document.createElement("div");
$(alertFram).attr('id', 'confirmFram');
$(alertFram).attr('class', 'alert alert-block');
$(alertFram).width('300px');
$(alertFram).height('100px');
$(alertFram).css({
"position":"absolute",
"left":"40%",
"top":"30%",
"margin-left":"-75px",
"text-align":"center",
"line-height":"50px",
});
strHtml = ' <h4 class="alert-heading">警告!</h4>';
strHtml += msg;
strHtml += "<p> <input type=\"button\" class=\"btn btn-danger\" value=\"确 定\" onclick=\"ok()\" />";
strHtml += " <input type=\"button\" class=\"btn btn-danger\" value=\"取消\" onclick=\"cancel()\" />";
$(alertFram).html(strHtml);
$('body').append(alertFram);
this.ok = function()
{
$(alertFram).hide();
return true;
}
this.cancel = function()
{
$(alertFram).hide();
return false;
}

return false;
}

有会的朋友帮帮忙吧

[解决办法]
你那个点击按钮会出错,作用域不同

你这个confirm和系统的confirm不一样,需要传递回调函数执行,return true/false没有意义,自己好好研究下js基础

JScript code
 function Confirm(msg,funok,funcancel) {/////////////....        this.ok = function () {            alertFram.hide();if(typeof funok=='function')funok();///////            return true;        }        this.cancel = function () {            alertFram.hide();if(typeof funcancel=='function')funcancel();///////            return false;        }}new Confirm('abc',function(){alert('点击确定按钮!')},function(){alert('点击取消按钮!')});
[解决办法]
http://www.scscms.com/article/2012-2/2317569957.html试试我写的吧,而且是美化版。模拟alert集警告、信息、错误、提问效果。
[解决办法]
探讨

引用:

http://www.scscms.com/article/2012-2/2317569957.html试试我写的吧,而且是美化版。模拟alert集警告、信息、错误、提问效果。

这个弹框效果不错,可是必须要加两个参数吗?confirm是怎么实现通过点击“确认”和“取消”来return true和false的?

读书人网 >JavaScript

热点推荐