简体   繁体   English

在 URL 中使用锚点或数据过滤器

[英]Use anchor or data-filter in URL

I have a button in a menu that sorts items listed below it.我在菜单中有一个按钮,可以对它下面列出的项目进行排序。 In this case the button says "news".在这种情况下,按钮显示“新闻”。 By using the data-filter attribute or naming it some certain way, can I go to this specific page with this button clicked so that the items are sorted in the way that this button represents?通过使用 data-filter 属性或以某种方式命名它,我可以在单击此按钮的情况下转到此特定页面,以便按此按钮表示的方式对项目进行排序吗?

Can I use anything in to not only scroll here, but also click the link?我可以使用任何内容不仅在此处滚动,还可以单击链接吗? Preferably by just using the URL.最好只使用 URL。

Thanks in advance.提前致谢。

In general lines:在一般线路中:

  1. Define a query string that would represent the desirable action (in your case sort).定义一个表示所需操作的查询字符串(在您的情况下排序)。 For instance: sort=news例如: sort=news
  2. On page load - fetch the query string of the page and extract sort .在页面加载 - 获取页面的查询字符串并提取sort ( see MDN for details ) 详见 MDN
  3. If sort contains a value - trigger the sort functionality如果 sort 包含一个值 - 触发排序功能

That should do the trick这应该够了吧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM