History.js + Forms?

Tho*_*omK 5 ajax jquery history.js

我们正在从jQuery Ajaxy迁移到History.js.Ajaxy有聪明的形式管理.有没有人有过如何将History.js集成到流程表单的示例?

Gre*_*nko 0

History.js 本质上是一个跨浏览器 shim,允许您使用 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");

}
Run Code Online (Sandbox Code Playgroud)

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

// 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

        });
    }
Run Code Online (Sandbox Code Playgroud)

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