鍍金池/ 問答/PHP  HTML/ jq重寫confirm函數(shù),怎樣讓函數(shù)返回true或fasle,目前返回不了

jq重寫confirm函數(shù),怎樣讓函數(shù)返回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;

}

有會的朋友幫幫忙吧

回答
編輯回答
忘了我

什么返回不了

2017年9月17日 08:17
編輯回答
夢一場

原生的alert,confirm是阻塞的
但自己寫的是通過事件點擊確定之后關(guān)閉,算是異步的一種所以不能直接返回
一般通過回調(diào)實現(xiàn)

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){}
});
2017年9月15日 04:33