Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery地址返回按钮_Jquery - Fatal编程技术网

jQuery地址返回按钮

jQuery地址返回按钮,jquery,Jquery,大家好,我正在尝试让AJAX网站&jquery.address-1.3.2.min.js正常工作 我有.click()事件,使用.load更新一个正在成功工作的DIV。 我已经用eg:rel=“address:profile”更新了,当我点击不同的链接时,我可以看到URL的变化 我还将此代码放入: $(function() { $.address.change(function(event) { alert('here'); }); }); 我可以看到正在触发.change()

大家好,我正在尝试让AJAX网站&jquery.address-1.3.2.min.js正常工作

我有.click()事件,使用.load更新一个正在成功工作的DIV。 我已经用eg:rel=“address:profile”更新了,当我点击不同的链接时,我可以看到URL的变化

我还将此代码放入:

$(function() {
  $.address.change(function(event) {
    alert('here');
  });
});
我可以看到正在触发.change()事件

我不确定如何编写代码来让后退/前进按钮实际工作(对不起,我是JQUERY新手)。我在网上看到过一些例子,但仍然很困惑。希望是一个非常简单的例子

我还需要重新运行.load()以再次加载DIV。也就是说,警报触发器并不是孤立于后退或前进浏览器按钮的点击


谢谢你

我没有真正理解你的问题,但是如果你想让后退按钮在ajax页面上工作(例如你改变了散列并用后退按钮返回到上一个页面),我建议使用


有一些很好的教程,对我来说非常有用。

现在您需要对
$.address.change()
事件中的div进行必要的更改,以转到所需的状态,所有页面状态更改都会进入该事件中

在jquery address中,您需要执行两个基本任务,首先,让您的链接更改深度链接值,使用与您相同的事件,但让它们更新
$.address.value(这里的value_)
方法;其次,使用
change()
事件捕获所有更改,以将更改应用于页面状态

例如,您还可以使用
value()
属性来确定正确的状态

$("a").onClick(function () {            //You dont need this part if you used
  $address.value($(this).attr('href')); //the 'rel' attribute in the links
});

$.address.change(function(event) {     //Catching URL change in `event`
  $.ajax({                             //You said you're using AJAX so
    url: "."+event.value+".html",      //using `value` attr. to get the URL+html
    cache: true,
    success: function(response) {
      $("#content_div").html(response);    //loading page in div using AJAX
    }
  });
});
这只是一个示例,您可以使用它以任何其他方式加载页面,因为
$.address.value()
返回深度链接值
#
后面的值

完成此操作后,“后退”和“前进”按钮将更改页面的URL,
change()
事件将捕获该URL,您的页面将按预期工作


因此,基本上,您需要对jquery地址的工作原理有一定程度的了解,并在其周围使用您的代码。另外,jquery地址文档页面有一个所有方法和事件的列表,以防您忘记其中任何一个。

当选择订阅哈希更改的插件时,请注意,新版本的jquery不支持浏览器检测,它们与功能检测一起工作。因此,一些旧插件不再工作。当我想使用jQuery地址时,这种情况就发生了。 为我工作的插件名为Path.js()。 我的上下文是:一个包含多个步骤的页面,我希望能够使用浏览器的“后退”按钮返回到以前的状态。我是这样配置的:

 Path.map("#2").to(function () {
        showStep2Page(); // hides the current DIV and shows the step 2 DIV
    });
    Path.map("#1").to(function () {
        showStep1Page();
    });
    Path.map("").to(function () { // this allows me to go to the first step and show the step 1 DIV 
        showStep1Page();
    });
    Path.listen(); // listens to changes in URL hash (after the pound sign (#))

因此,您希望将某个内容加载到DIV中,然后单击“上一步”按钮(例如)以恢复之前的DIV?不要真正理解你的问题;)