1

在此示例中,如何使用 Jquery 单击“取消”按钮来调用函数并让对话框不断返回?我相信这很容易,但仍然在这里学习一些基础知识。谢谢

function definitelyClose() {
    window.location = 'http://www.google.com'
};
var autoCloseTimer;
var timeoutObject;
var timePeriod = 5000;
var warnPeriod = 10000;
$(document).ready(function() {
    $('#proba').dialog({
        autoOpen: false
    });
    setTimeout(function() {
        $('#proba').attr('title', 'Warning').text('Sesion will expire').dialog('open');
        $('#proba').dialog({
            buttons: {
                'Cancel': function() {
                    $(this).dialog('close');
                    clearTimeout(autoCloseTimer);
                }
            }
        });
        autoCloseTimer = setTimeout('definitelyClose()', warnPeriod);
    }, timePeriod);
});​
4

1 回答 1

1

您需要创建具有名称的函数

  1. 显示初始警告和
  2. 单击取消按钮时调用。

所以你会得到这样的东西:

$(document).ready(function() {
  var autoCloseTimer;
  var timePeriod = 5000;
  var warnPeriod = 10000;

  function definitelyClose() {
    window.location = 'http://www.google.com'
  };

  // You need a function with a name
  function showWarning() {
    $('#proba').attr('title', 'Warning')
               .text('Sesion will expire')
               .dialog('open');
    $('#proba').dialog({
      buttons: {
        'Cancel': function() {
          $(this).dialog('close');
          clearTimeout(autoCloseTimer);
          // Now you can recall the function
          setTimeout(showWarning, timePeriod);
        }
      }
    });
    autoCloseTimer = setTimeout(definitelyClose, warnPeriod);
  }

  $('#proba').dialog({ autoOpen: false });
  setTimeout(showWarning, timePeriod);
});​
于 2012-09-02T09:36:43.533 回答