0
好的,所以我需要一些洞察与History.js和jQuery的工作。处理状态变化jQuery和History.js
我已经建立并运作(只是不像您期望的那样)。
我有如下:
$(function() {
var History = window.History;
if (!History.enabled) {
return false;
}
// Capture all the links to push their url to the history stack and trigger the StateChange Event
$('.ajax-link').click(function(e) {
e.preventDefault();
var url = this.href; //Tells us which page to load
var id = $(this).data('passid'); //Pass ID -- the ID in which to save in our state object
e.preventDefault();
console.log('url: '+url+' id:'+id);
History.pushState({ 'passid' : id }, $(this).text(), url);
});
History.Adapter.bind(window, 'statechange', function() {
console.log('state changed');
var State = History.getState(),
id = State.data.editid; //the ID passed, if available
$.get(State.url,
{ id: State.data.passid },
function(response) {
$('#subContent').fadeOut(200, function(){
var newContent = $(response).find('#subContent').html();
$('#subContent').html(newContent);
var scripts = $('script');
scripts.each(function(i) {
jQuery.globalEval($(this).text());
});
$('#subContent').fadeIn(200);
});
});
});
}); //end dom ready
它可以作为你只要更改URL,传递的ID,改变内容的期望。我的问题是这样的: 如果我在浏览器上向前/向后按几次subContent部分将基本上淡入/淡出多次。
任何洞察力是赞赏。谢谢
============================================= ======
编辑:问题是在我打电话给我的所有<script>
和Eval他们在每个状态变化。通过添加类=“无重载”的历史管理脚本标签我是能够做到:
var scripts = $('script').not('.no-reload');
这摆脱了问题,现在按预期工作。图一我会在这里留下来,以防其他人遇到同样的问题。
我们不会在SO上的标题中做“(已解决)”。如果您能够回答自己的问题,您可以添加答案并将其标记为已接受,或者您可以删除该问题。 – j08691
好的,我试图编辑它并添加一个答案,但我不知道我应该回答我自己的主题与答案。原帖中没有办法做到这一点吗? – Imperialized
http://meta.stackexchange.com/questions/17845/etiquette-for-answering-your-own-question和http://meta.stackexchange.com/questions/17463/can-i-answer-my-own -questions偶数如果-I-知道最答案前方的问 – j08691