jquery - History.js + 表单?

标签 jquery ajax history.js

我们正在从 jQuery Ajaxy 迁移至 History.js 。 Ajaxy 具有智能表单管理。有人有如何集成 History.js 来处理表单的示例吗?

最佳答案

History.js 本质上是一个跨浏览器填充程序,允许您使用 HTML5 History API,并且它不专门提供任何内置表单管理逻辑。因此,如果您想使用它来管理表单状态,则必须手动将历史记录条目添加到浏览器历史记录对象中,如下所示:

// If the History.js plugin has been included on the page
if(window.History) {

    // Adds a new state and url to the browser history object
    // Eg. If your page was index.html... it becomes index.html?someState
    window.History.pushState(null, $(this).attr("data-href"), "?someState");

}

如果您有一些在状态更改发生时需要发生的自定义逻辑,您可以执行以下操作:

// If the History.js plugin has been included on the page

    if(window.History) {

        // Binds to the StateChange Event
        window.History.Adapter.bind(window,'statechange',function() {

            // Do something

        });
    }

有关 History.js 的更多信息,请查看 History.js github page

关于jquery - History.js + 表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6496435/

相关文章:

javascript - 使用ajax动态更新表格行的值

javascript - 如何使用 jquery 将标题大小写文本输出到 html 字段中

javascript - 如何从指令更新 $scope 值

ajax - 如何验证数据库中用户名的可用性?

javascript - 使用history.js,以便我可以在网站上进行深层链接

ruby-on-rails - 如何以正确的方式在 Rails 中执行 history.js?

javascript - 将图像插入到 DOM,大小调整为其宽度/高度的 50%

JavaScript 代码签名

javascript - 如何使用 javascript/ajax 拖放后更新数据库?

ajax - 具有 SEO 友好的 ajax 和历史记录的单页网站