我们正在从 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/