jq重写confirm函数,怎样让函数返回true或fasle,目前返回不了

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;

}

有会的朋友帮帮忙吧

阅读 2.7k
2 个回答

原生的alert,confirm是阻塞的
但自己写的是通过事件点击确定之后关闭,算是异步的一种所以不能直接返回
一般通过回调实现

function Confirm(msg,option)
{
     this.ok = function()
    {
        $(alertFram).hide();
        option.ok(true);
    }
    this.cancel = function()
    {
        $(alertFram).hide();
        option.cancel(false);
    }
}

Confirm('你好',{
    ok:function(a){},
    cancel:function(a){}
});

什么返回不了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题