javascript - 我如何从 jQuery 中的模态对话框中获取结果

标签 javascript jquery ajax jquery-ui simplemodal

我想在 UI 工具包中使用简单模态或对话框插件之类的插件。但是,我如何使用这些或任何其他并获得结果。基本上我希望模态与服务器进行一些 AJAX 交互并返回调用代码的结果以执行一些操作。

最佳答案

这是确认窗口在 simpleModal 上的工作方式:

$(document).ready(function () {
  $('#confirmDialog input:eq(0)').click(function (e) {
    e.preventDefault();

    // example of calling the confirm function
    // you must use a callback function to perform the "yes" action
    confirm("Continue to the SimpleModal Project page?", function () {
      window.location.href = 'http://www.ericmmartin.com/projects/simplemodal/';
    });
  });
});

function confirm(message, callback) {
  $('#confirm').modal({
    close: false,
    overlayId: 'confirmModalOverlay',
    containerId: 'confirmModalContainer', 
    onShow: function (dialog) {
      dialog.data.find('.message').append(message);

      // if the user clicks "yes"
      dialog.data.find('.yes').click(function () {
        // call the callback
        if ($.isFunction(callback)) {
          callback.apply();
        }
        // close the dialog
        $.modal.close();
      });
    }
  });
}

关于javascript - 我如何从 jQuery 中的模态对话框中获取结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50097/

相关文章:

javascript - 使用 JWT Token、React Native 和 Redux 检索用户信息

php - 从浏览器获取唯一标识符

javascript - 如何在javascript中使用preventDefault删除默认操作?

javascript - 为 Ajax 实时搜索添加箭头导航

jquery - 从 AJAX 的许多页面中序列化独特的表单。适用于 FF/Safari,但 IE 会序列化页面上的所有表单

jquery - 经典的asp文件上传与jquery优点?

javascript - 将字符串的部分与对象数组匹配

javascript - 我什么时候应该使用 KnockoutJS 组件和模板?

JavaScript - 替换名称属性中第一个方括号之间的值

javascript - jquery按钮点击功能自动延时