简体   繁体   English

Javascript,无法动态更改产品页面

[英]Javascript, cannot change product pages dynamically

I am teaching myself Javascript at the moment and I am creating a small website project for fun.我目前正在自学 Javascript,并且我正在创建一个小型网站项目以供娱乐。 My issue is:我的问题是:

I have a homepage that has a button in a navbar called "Products".我有一个主页,在导航栏中有一个名为“产品”的按钮。 When I press it, I am redirected in a page where I have a grid layout with 5-6 categories (as images).当我按下它时,我被重定向到一个页面,其中我有一个包含 5-6 个类别(作为图像)的网格布局。 When I press the images, I am redirected to the relevant products.当我按下图像时,我被重定向到相关产品。 For example Products > Cars > Fiesta 2009 and more cars.例如产品 > 汽车 > Fiesta 2009 和更多汽车。

The thing is that for every different product category I have a different HTML page, but I know that I can just have an HTML page and change its content dynamically(DOM).问题是,对于每个不同的产品类别,我都有一个不同的 HTML 页面,但我知道我可以只拥有一个 HTML 页面并动态更改其内容(DOM)。 Is there a good guide that describes this specific functionality?是否有描述此特定功能的好指南? I have tried many different approaches but I don't really know how to do that and my site doesn't work.我尝试了许多不同的方法,但我真的不知道该怎么做,而且我的网站无法正常工作。

Posting it after 15 hours on working on my code and not finding a solution myself*在处理我的代码 15 小时后发布它,但我自己没有找到解决方案*

You can consider using a UI framework/library such as ReactJS, Angular... Then use a routing handler (react-router, @angular/router...).您可以考虑使用 UI 框架/库,例如 ReactJS、Angular... 然后使用路由处理程序(react-router、@angular/router...)。

Another alternative is to use plain javascript (VanillaJS).另一种选择是使用普通的 javascript (VanillaJS)。 I submitted a sample few days ago nearly around this topic.几天前,我几乎围绕这个主题提交了一个样本

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

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