如何使用 CSS 一次显示和隐藏多个元素?
我找到了这篇文章这看起来正是我想要的,但我似乎根本无法让它工作。由于它已经存在一年多了,我想也许有些东西已经改变了,或者现在可能有一种更简单的方法来做到这一点。
也就是说,我无法使上面链接的方法起作用。我完全复制并粘贴,并使用 因为我不确定
$(document).ready(function ()...不幸的是,我本来应该去的,我对 Javascript 很不熟悉。
I found this article that looked like exactly what I wanted, but I can't seem to get it to work at all. Since it is well over a year old, I thought perhaps something may have changed, or that there might be a simpler way to do it by now.
That is to say, I cannot get the method I linked above to work. I copied and pasted exactly, and used <body onLoad="javascript_needed()">
because I wasn't sure where $(document).ready(function ()...
was supposed to go. I am, sadly, quite unfamiliar with Javascript.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用这样的东西;
从 http://jquery.com/ 加载 jQuery 库。
不要忘记同时 想要阅读选择器。
使用
$("#myElement")
将选择 id 为“myElement”的元素。使用
$(".myElement")
将选择具有“myElement”类的元素。所以;
编辑
如果你想在线链接到 jquery 库,那么使用;
如果您下载该库并将 js 文件插入到您的项目中,然后使用;
Use something like this;
Don't forget to load the jQuery library at the same time from http://jquery.com/
Also, you are going to want to read up on selectors.
Using
$("#myElement")
will select elements that have an id of "myElement".Using
$(".myElement")
will select elements that have a class of "myElement".So;
edit
If you want to link to the jquery library online then use;
If you download the library and insert the js file into your project then use;
$
语法是 jQuery 的一部分。如果您希望在代码中的某个位置使用 jQuery,请使用脚本标记,如您的帖子中所示:如果您想要纯 JavaScript,则需要更多的开销。不包括文档准备好的东西(这可能需要很多额外的代码才能正确完成......参见示例:此处)。
如果您愿意,可以将其放入函数中。要显示元素,请将显示属性设置为
''
。The
$
syntax is all part of jQuery. If you wish to use jQuery then somewhere in your code, use a script tag as in your post:If you want pure JavaScript, then there is a little more overhead. Not including the document ready stuff (which can be a lot of extra code to do it right...See example: here).
You can put that in a function if you would like. To show the elements set the display attribute to
''
.