【问题标题】:How to call fucntion when modal close JQuery模态关闭JQuery时如何调用函数
【发布时间】:2019-11-18 07:41:13
【问题描述】:

模态关闭时我需要调用一个函数。我的代码如下,

function openModal(divName) {
        $("#"+divName+"Modal").modal({
        overlayClose: false,
        closeHTML: "<a href='#' title='Close' class='modal-close'>X</a>",
        onShow: function (dialog) {
            $('#simplemodal-container').css({ 'width': 'auto', 'height': 'auto', 'padding-bottom': '1000px' });
            var tmpW = $('#simplemodal-container').width() / 2
            var tmpH = $('#simplemodal-container').height() / 2
            $('#simplemodal-container').css({ 'margin-left': tmpW * -1, 'margin-top': tmpH * -1 });
            },
        close:onClose,
        onClose: ModalClose(),
        opacity: 50,
        persist: true
    });
}

我尝试了以下两种调用函数的方法,但都不起作用

第一种方式

function onClose() {
   alert('called');
}

第二种方式

$('.resetbutton').click(function () {
   alert('called');
}

【问题讨论】:

  • 你用的是什么模态插件?
  • @PatrickEvans 我正在使用剑道
  • 更改 closeHTML: "X",
  • onClose: ModalClose(), 应该是:onClose: ModalClose,

标签: javascript jquery function onclick modal-dialog


【解决方案1】:

在 ModalClose() 中调用另一个你想要的函数,如果它是用户定义的函数

【讨论】:

    【解决方案2】:

    从引导文档中,您可以在关闭模式Javascript.Bootstrap时调用javascript事件@

    $('#myModal').on('hide.bs.modal', function (e) {
      // do the closing function...
    });
    

    对于剑道图书馆,您可以关闭但没有“()”,这将在函数中传递事件“e”

    关闭:关闭,

    Events in Kendo UI

    dialog.kendoDialog({
        width: "400px",
        title: "Software Update",
        closable: true,
        modal: false,
        content: "<p>A new version of <strong>Kendo UI</strong> is available. Would you like to download and install it now?<p>",
        actions: [
            { text: 'Close', action: onCancel },
            { text: 'OK', primary: true, action: onOK }
        ],
        initOpen: onInitOpen,
        open: onOpen,
        close: onClose,
        show: onShow,
        hide: onHide
    });
    
    function onClose(e) {
        show.fadeIn();
        kendoConsole.log("event :: close");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-05
      • 2019-10-07
      • 2016-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-27
      • 1970-01-01
      相关资源
      最近更新 更多