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;

}


有会的朋友帮帮忙吧


临摹微笑
浏览 978回答 1
1回答

心有法竹

原生的alert,confirm是阻塞的但自己写的是通过事件点击确定之后关闭,算是异步的一种所以不能直接返回一般通过回调实现function Confirm(msg,option){&nbsp; &nbsp; &nbsp;this.ok = function()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $(alertFram).hide();&nbsp; &nbsp; &nbsp; &nbsp; option.ok(true);&nbsp; &nbsp; }&nbsp; &nbsp; this.cancel = function()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $(alertFram).hide();&nbsp; &nbsp; &nbsp; &nbsp; option.cancel(false);&nbsp; &nbsp; }}Confirm('你好',{&nbsp; &nbsp; ok:function(a){},&nbsp; &nbsp; cancel:function(a){}});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript