无法理解 History.js,需要简化吗?

发布于 2024-12-03 14:47:26 字数 420 浏览 1 评论 0 原文

我对编程相当陌生,我正在 jQuery 的帮助下制作一个 AJAX 网站。

我已经查看了相当多的 AJAX 历史处理程序,并认为 History.js 似乎是最好/最新的。

我的菜单按钮每个都有自己唯一的 ID(#homeBtn、#featuresBtn、#pricingBtn),目前如下所示:

有人能给我举个例子吗(最好是在 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反目相谮 2024-12-10 14:47:26

请按照此处的说明进行操作: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" to href="/home" - make sure http://mywebsite.com/home works. This is all about graceful up-gradation.

青春如此纠结 2024-12-10 14:47:26

我认为您需要的“简化”版本是路由器抽象。我出于自己的目的编写了一个简单的代码,名为 StateRouter.js。它基本上负责将应用程序支持的 URL 定向到正确的功能,您甚至可以定义路由的参数部分(例如 http://example.com/persons/id 成为函数参数)。

这个简单的示例代码应该演示如何使用它:

var router = new staterouter.Router();
// Configure routes
router
  .route('/', getHome)
  .route('/persons', getPersons)
  .route('/persons/:id', getPerson);
// Perform routing of the current state
router.perform();
// Navigate to the page of person 1
router.navigate('/persons/1');

这是我为了演示而编写的一些 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:

var router = new staterouter.Router();
// Configure routes
router
  .route('/', getHome)
  .route('/persons', getPersons)
  .route('/persons/:id', getPerson);
// Perform routing of the current state
router.perform();
// Navigate to the page of person 1
router.navigate('/persons/1');

Here's a little fiddle I've concocted in order to demonstrate its usage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文