简体   繁体   中英

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?

Can I use anything in to not only scroll here, but also click the link? Preferably by just using the 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
  2. On page load - fetch the query string of the page and extract sort . ( see MDN for details )
  3. If sort contains a value - trigger the sort functionality

That should do the trick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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