2011-08-21 34 views
0

我使用jquery.address()通过Ajax加载我的网页:jQuery的地址找到点击了哪个元素

$ .address.state( '')的init(函数(){

// 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()。这工作真的没事至今苍蝇。

但是我有一个#next和#nextprev内的#prev元素。我想要找到他们哪个被点击,然后加载一个不同的函数(即startAnimation2())。

回答

0

你需要在一个标记属性来定义(或在一个隐藏的输入/本地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> 
+0

酷是类似的东西。我也已经考虑过cookies,但是我想为#next和#prev有两种不同的动画类型。我如何知道哪些是实际点击?该标记只会提供一种动画类型.... – Mike

+0

已编辑帖子。你可以做它,因为它显示或使用多个输入元素。 – yoda

+0

嗯好吧,我会尝试。谢谢尤达! – Mike