简体   繁体   English

如何使用 HTML/CSS/Javascript 在同一页面上的内容之间切换?

[英]How can I switch between content on the same page using HTML/CSS/Javascript?

I want to show different content for when the user switches between different month/year options within the same page.当用户在同一页面内的不同月份/年份选项之间切换时,我想显示不同的内容。 eg I want to show the user events for the month of March 2021 if he /she chooses that option.例如,如果他/她选择该选项,我想显示 2021 年 3 月的用户事件。 Attached is the screenshot for reference of how I want the UI to look like.附件是我希望 UI 看起来如何的屏幕截图,以供参考。

在此处输入图像描述

As far as I know, doing this with vanilla html,css,js is pretty hard.据我所知,用香草 html,css,js 做这件事是相当困难的。 What you can do is using a <div> for every month and use css to set all of them to display: none except the one that should be shown.您可以做的是每个月使用一个<div>并使用 css 将所有这些设置为display: none Then you could attach an onclick listener to your two arrow keys.然后,您可以将onclick侦听器连接到您的两个箭头键。 With javascript you can then make your current month <div> hidden and show your next month with display: block .使用 javascript 您可以隐藏当前月份<div>并使用display: block下个月。 You have to watch out that all your seperate month containers are position: absolute at exactly the same place.您必须注意所有单独的月份容器都是position: absolute在同一个地方。

Watch out, this is a really not ideal solution especially if you have a lot of containers.请注意,这确实不是一个理想的解决方案,尤其是在您有很多容器的情况下。

The proper way to do this would be using something like ReactJS or you could also try Ajax .正确的方法是使用ReactJS之类的东西,或者您也可以尝试Ajax Both allow you to change part of your website without having to reload it completely.两者都允许您更改网站的一部分,而无需完全重新加载。

This is just how you can do it.这就是你可以做到的。 Don't expect anyone on the forum here to do the work for you.不要指望论坛上的任何人为您完成工作。 If you have specific questions or problems, feel free to ask but this is not a platform to get free workers.如果您有具体的问题或问题,请随时提出,但这不是获得免费工人的平台。

暂无
暂无

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

相关问题 从仅使用 JavaScript/HTML 的表单重定向后,如何修改 HTML 页面的内容? - How can I modify the content of an HTML page after redirecting from a form using only JavaScript/HTML? 如何在JavaScript的同一页面上显示文本内容? - How can I display text content on the same page in JavaScript? 如何使用javascript更改html页面的“ h1”标签的内容? - How can I change the content of the “h1” tag of an html page using javascript? 在与Aurelia相同的区域中单击按钮时,如何切换页面上的内容区域? - How can I switch out the content area on a page on a button click in the same area with Aurelia? 在使用 css、javascript 和 ZE1BFD762321E409CEEZ4AC0B66 时,我如何限制 HTML 表的打印页面中的特定行数 - how can i restrict no of specific rows in print page for a HTML table in using css , javascript and php 如何使用 HTML、CSS 和 Javascript 创建动态产品页面 - How can I create a dynamic product page using HTML, CSS, and Javascript 如何使用JavaScript在同一个页面上的两个内容之间淡入和淡出? - How can I fade-in and fade-out between two contents on same page using javascript? 如何仅使用CSS / JS将内容添加到页面? - How can I add content to the page by just using css/js? 如何修改 CSS 标记内容? 不使用 JavaScript? - How can I modify a CSS tag content? Without using JavaScript? 如何使用外部Javascript在CSS文件之间切换 - How to switch between CSS files using external Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM