【问题标题】:jQuery Address find out which element was clickedjQuery地址找出哪个元素被点击
【发布时间】:2011-08-21 13:23:52
【问题描述】:

我使用 jquery.address() 通过 ajax 加载我的页面:

$.address.state('').init(function() {

// Initializes the plugin
$('#menu a').address();
$('#nextprev a').address();

}).change(function(event) {

// Loads the page content and inserts it into the content area
$.ajax({
    url: $.address.state() + event.path,
    error: function(XMLHttpRequest, textStatus, errorThrown) {
      console.log(XMLHttpRequest.responseText);
    },
    success: function(data, textStatus, XMLHttpRequest) {
      $('title').html($('title', data).html());
      $.address.title(/>([^<]*)<\/title/.exec(data)[1]);
      $('#content').html($('#content', data).html());
      loadstuff();
      startAnimation();
    }
});

var startAnimation = function(data) {
... some animation going on here
});

目前代码调用ajax加载下一页后,通过startAnimation()飞入下一页。到目前为止效果很好。

但是我在#nextprev 中有一个#next 和一个#prev 元素。我要地址找出它们中的哪一个被点击,然后加载不同的函数(即startAnimation2())。

【问题讨论】:

    标签: jquery jquery-address


    【解决方案1】:

    您需要在标记属性中(或在隐藏的输入/本地 PC 内存中)定义当前动画索引,类似于:

    <input type="hidden" value="3" name="current-animation" />
    

    然后获取值:

    $('input[name="current-animation"]').val();
    

    带有标记的替代方案:

    <div id="animation-data" data-current="3" data-animation="animation-1"></div>
    

    【讨论】:

    • 酷是这样的。我也已经考虑过 cookie,但我希望 #next 和 #prev 有 2 种不同的动画类型。如何找出实际点击的内容?标记只会提供一种动画类型....
    • 帖子已编辑。您可以按照显示的方式进行操作,也可以使用多个输入元素。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 1970-01-01
    • 2021-03-20
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多