有没有JavaScript动态更改内容的方法? [英] Is there a way to dynamically change content without javascript?

查看:158
本文介绍了有没有JavaScript动态更改内容的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个工作页面,其中包含内容需要根据按钮点击动态更改的部分。我知道几种不同的方式来完成这一切,但所有这些都涉及某种或某种类型的javascript。我的能力目前不包括为这个网站编写脚本,所以我正在研究,以确定是否有办法做到这一点与JUST css之前,通知我的项目经理,我们的一个JavaScript的人将不得不处理它。所以,任何人都知道可能会获得所需效果的任何酷CSS技术?

I am building out a page for work that has a section where the content needs to change dynamically on button(s) click. I know of several different ways to accomplish this but all of them involve javascript of some kind or another. My capabilities don't currently include writing script for this site so I am researching to see if there is a way to do this with JUST css before I inform my project manager that one of our javascript guys will have to handle it. So, anyone know of any cool CSS techniques that might get the desired effect?

推荐答案

你可能会使用CSS的 :target 伪类选择器。这将需要用一个元素替换您的按钮,这会导致您的文档的URL应用与 id相关的哈希值要更改的元素的属性。

You could potentially use CSS's :target pseudo-class selector. This would require replacing your buttons with a elements instead, which cause your document's URL to apply a hash relating to the id attribute of the element you want to change.

div {
  display: none;
}

:target {
  display: block;
}

<a href="#foo">Click here to show the hidden <code>div</code> element</a><br>
<a href="#">Click here to hide it again</a>.
<div id="foo">This should only show when the link is clicked.</div>

这篇关于有没有JavaScript动态更改内容的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆