首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >History.js +表单?

History.js +表单?
EN

Stack Overflow用户
提问于 2011-06-27 17:14:13
回答 1查看 976关注 0票数 5

我们正在从jQuery阿基西迁移到History.js。Ajaxy拥有智能的表单管理。有谁有如何集成History.js来处理表单的示例吗?

EN

回答 1

Stack Overflow用户

发布于 2012-06-12 14:17:51

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

代码语言:javascript
复制
// 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");

}

如果您有一些需要在发生状态更改时发生的自定义逻辑,您可以这样做:

代码语言:javascript
复制
// 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页面

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6496435

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档