主函数参数中的JavaScript推入结果供确认使用

问题描述 投票:0回答:1

很抱歉,我在javascript和jquery方面还很新...

我想知道如何通过单击“按下”按钮将确认框的点击结果推送到我的主要功能中?

<button class="btn">Press</button>
<div id="box" class="modal">
  <div class="modal-dialog">
    <button>Cancel</button>
    <button class="modal-btn-confirm">Ok</button>
  </div>
</div>
var confirmQuestion = function(result) {
    var resultA = [];
    $('#box').modal('show');

    function result(){
        $('#box').find('.modal-btn-confirm').on('click', function(e) {
            resultA.push(true);
            $(this).modal('hide');
        });          
    }
    if(result){
        return result(); 
    }
}

$('.btn').on('click', function (event) {
    confirmQuestion(function(result){
       if(result){
           //code ok
       }else{
           //code not ok
       }  
    });
});

非常感谢!

javascript jquery modal-dialog confirm
1个回答
0
投票

正如我在评论中提到的,在'Press'btn单击上-打开模式,然后在'OK'上将结果推送到'resultA'数组

© www.soinside.com 2019 - 2024. All rights reserved.