0

我有这个非常简单的 jQuery 脚本来更改基于链接的模式内容。代码:

$('#facebook-friends').on('hidden', function () {
  $(this).removeData('modal');
});

然后我可以根据按钮控制将使用哪些内容:

<a href="facebook-frame.php" id="full-width" data-target="#facebook-friends" role="button" class="btn btn-primary" data-toggle="modal"><i class="icon-facebook"></i> Use Facebook</a>

它完美地工作!但是,我在此facebook-frame.php文件中有链接,并且我希望所有操作都保留在模式中,这样外部页面就不会重新加载。

我已经在里面尝试过这个解决方案,facebook-frame.php但它不起作用。

<a href="facebook-frame.php?all" data-target="#facebook-friends" role="button" class="btn btn-primary" data-toggle="modal">

这是我主页上的模式:

    <div class="modal fade hide" id="facebook-friends" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Inviter veninder fra Facebook</h3>
  </div>
  <div class="modal-body text-center">
    <p>Loading content...</p>
<p><IMG src="ajax-loader.gif"></p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Luk</button>
  </div>
    </div>

我特别喜欢“加载内容”,因为它看起来很有活力。

有什么方法可以为内部的链接/按钮分配一个特殊的命令/类/名称,facebook-frame.php以便在单击时会临时显示“正在加载内容”,然后同时加载请求的页面(内部href属性)?

4

1 回答 1

0

如果我理解正确,facebook-frame.php你可以像这样捕获所有<a>(或特定<a>类)点击事件吗?

$(document).on('click', '#facebook-friends a', function(e) {
    e.preventDefault();
    // show the "Loading content" message
    // load the content and whatever else you need to do
});

注意:.on()需要 jQuery 1.7+。在此之前,您将使用.live().

于 2013-03-09T22:26:34.353 回答