我对编程相当陌生,我正在 jQuery 的帮助下制作一个 AJAX 网站。
我已经查看了相当多的 AJAX 历史处理程序,并认为 History.js 似乎是最好/最新的。
我的菜单按钮每个都有自己唯一的 ID(#homeBtn、#featuresBtn、#pricingBtn),目前如下所示:
Home
有人能给我举个例子吗(最好是在 jsfiddle 上)我将如何实现 History.js?
我似乎无法理解作者给出的任何示例,我只需要一个简化版本=b
如果您需要更多信息,请告诉我,谢谢!
I'm fairly new to programming, and I'm making an AJAX site with the help of jQuery.
I've looked around a fair bit for an AJAX history handler, and figured that History.js seems to be the best/most up-to-date.
My menu buttons each have their own unique ID's (#homeBtn, #featuresBtn, #pricingBtn), and currently look like this:
<a href="#home" class="homeMainMenuButton" id="homeBtn"><div class="homeMainMenuButtonText">Home</div></a>
Can someone give me an example (preferably on jsfiddle) on how I would implement History.js?
I can't seem to grasp any of the examples given by the author, and I simply need a dumbed down version =b
If you need any more information, please let me know, and thanks!
发布评论
评论(2)
请按照此处的说明进行操作:https://github.com/browserstate/ajaxify
将链接更改为传统链接< code>href="#home" 到
href="/home"
- 确保http://mywebsite.com/home
有效。这都是关于优雅的升级。Follow the instructions here: https://github.com/browserstate/ajaxify
Change your links to traditional links
href="#home"
tohref="/home"
- make surehttp://mywebsite.com/home
works. This is all about graceful up-gradation.我认为您需要的“简化”版本是路由器抽象。我出于自己的目的编写了一个简单的代码,名为 StateRouter.js。它基本上负责将应用程序支持的 URL 定向到正确的功能,您甚至可以定义路由的参数部分(例如 http://example.com/persons/id 成为函数参数)。
这个简单的示例代码应该演示如何使用它:
这是我为了演示而编写的一些 fiddle它的用法。
I think the "dumbed down" version you need is a router abstraction. I've written a simple one for my own purposes, called StateRouter.js. It basically takes care of directing URLs supported by your application to the correct functions, you can even define parameter parts of routes (so that e.g. the 'id' part of http://example.com/persons/id becomes a function parameter).
This simple example code should demonstrate how it's used:
Here's a little fiddle I've concocted in order to demonstrate its usage.