想要:可以显示三角形 的简单 HTML 文件隐藏/显示
我有一个可以生成文本报告的程序。我希望它制作一个包含多个显示三角形的 HTML 报告,这样当您单击三角形时,报告的更多内容就会显示或隐藏。我同意将 JavaScript 嵌入到文件中,但我真的希望将其全部放在一个文件中,而不需要其他文件。有没有一种简单的方法可以使用现代浏览器来做到这一点?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web
技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我有一个可以生成文本报告的程序。我希望它制作一个包含多个显示三角形的 HTML 报告,这样当您单击三角形时,报告的更多内容就会显示或隐藏。我同意将 JavaScript 嵌入到文件中,但我真的希望将其全部放在一个文件中,而不需要其他文件。有没有一种简单的方法可以使用现代浏览器来做到这一点?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的
隐私政策
了解更多相关信息。 单击
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文
发布评论
评论(5)
如果您不关心与 Internet Explorer 的兼容性,可以使用 html 标记: http:// www.w3schools.com/tags/tag_details.asp
这是一种制作披露三角形原型的非常快速的方法。
例如:
If you don't care about compatibility with Internet Explorer, you could use the html tag: http://www.w3schools.com/tags/tag_details.asp
Its a very quick way to prototype disclosure triangles.
For example:
最简单的方法是这样的:
我在这里做了一个简单的工作示例: http://jsfiddle.net/NXuQt /1/
它并不漂亮,但应该为您提供所需的简单模板。
请注意,在这个解决方案中,整个标题是可点击的...我认为添加图像并将其作为点击事件的一部分进行更改是您可以自行处理的事情,否则请告诉我:)
注意:javascript 是基于 jQuery 库的包含。
编辑:我更新了复制/粘贴就绪工作代码的答案,您无法使其按原样工作的原因是因为我只从小提琴示例中获取了要点。小提琴自动在 DOMready 上运行点击处理程序初始化,更新的示例现在已经内置了:)
The simplest way is something like this:
I have made a simple working example here: http://jsfiddle.net/NXuQt/1/
It isn't pretty but should give you the simple template you need.
Note that in this solution, the entire header is click-able... I figure adding an image and changing it as part of the click event is something you can take care of yoruself, otherwise let me know :)
Note: The javascript is based on the inclusion of the jQuery library.
EDIT: I updated the answer to copy/paste ready working code, the reason you couldn't make it work as it was, was because i had only taken the essentials from the fiddle example. The fiddle automatically ran the click handler initialization at DOMready, which the updated example now has built in :)
对于直接的 HTML,不行。那不是它的目的。您将需要使用脚本语言,很可能是 JavaScript 或 VBScript。
这是我过去使用过的脚本(不是我的,但我没有原始的 URI):
您可以将对toggleSlide() 的调用分配给要切换的元素的 onclick() 事件。
With straight HTML, no. That's not what it's for. You will need to use a scripting language, either JavaScript or VBScript, most likely.
This is a script I've used in the past (not mine, but I don't have the URI of the original):
You would assign a call to toggleSlide() to the onclick() event of the element you want to toggle.
CSS:
Javascript:
HTML:
显然你必须将一些东西更改为你自己的 html 文件
CSS:
Javascript:
HTML:
Obviously you would have to change some things to your own html file
好吧,经过一些摆弄,我能够使用我在 switchcontent.js 和
switchicon.js
javascript 文件创建一个可以执行我想要的操作的文件="http://www.dynamicdrive.com/dynamicindex17/switchcontent2.htm" rel="nofollow">http://www.dynamicdrive.com/dynamicindex17/switchcontent2.htm这是我的代码,基于编辑关闭他们的:
关闭时看起来像这样:
打开时看起来像这样:
Well, after some fiddling around, I was able to make a file that does what I want using the
switchcontent.js
andswitchicon.js
javascript files I found at http://www.dynamicdrive.com/dynamicindex17/switchcontent2.htmHere's my code, based on editing down theirs:
It looks like this when closed:
And this when opened: