jQuery 淡入段落
我想让我的文本在单击菜单链接时淡入。因此,当我单击“主页”时,我想淡入该文本,但它不起作用。我的代码有什么问题吗?
jQuery(function ($) {
$('a#homeactiv').click(function(){
$(this).find('p#paragraph').fadeIn(slow);
});
{
});
这是我的 html、css、jquery 的一部分: http://jsfiddle.net/35qwb/2/
I want to let my text fade in when click on a menu link. So when I click on "home" I want to fadeIn that text, but it doens't work. Whats wrong with my code?
jQuery(function ($) {
$('a#homeactiv').click(function(){
$(this).find('p#paragraph').fadeIn(slow);
});
{
});
Here is a part of my html,css,jquery: http://jsfiddle.net/35qwb/2/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
许多事情,包括但不限于:
$('#foo')
而不是$('a#foo')
。{
)。'slow'
两边加引号。这应该可行:
基本上你需要先学习 jQuery,然后再要求人们修复你的代码。您应该首先阅读许多初学者教程。
Many things, including but not limited to:
$('#foo')
NOT$('a#foo')
.{
).'slow'
.This should work:
Basically you need to learn jQuery before asking people to fix your code. There lots of beginner tutorials that you should read first.
摆脱 find,这不是 jQuery 应该如何运行的。此外,不要将 Slow 传递给函数,除非您有一个名为 Slow 的变量,它应该是字符串或数字。
如果您只是执行
$("#paragraph").fadeIn(slow)
,jQuery 将查找名为slow
的变量并将其传递给 fadeIn 方法。由于没有名为slow
的变量,它将传递 0,这意味着该方法应在 0 毫秒内运行,并立即显示。Get rid of the find, that's not how jQuery is supposed to run. Further, don't pass slow to the function unless you have a variable named slow, it's supposed to be a string or a number.
If you just do
$("#paragraph").fadeIn(slow)
jQuery will look for a variable calledslow
and pass it into the fadeIn method. As there is no variable calledslow
it will pass 0, meaning the method should run in 0 milliseconds, and show instantly.我相信您的代码中有语法错误,请尝试
此外,
$(this).find('p#paragraph')
只会找到p#paragraph
,即a#homeactiv
的后代。切换到简单查询 -$('#paragraph')
I believe that you have a syntax error in your code, try
Additionally,
$(this).find('p#paragraph')
would find onlyp#paragraph
that is a descendant ofa#homeactiv
. Switch to a simple query —$('#paragraph')
试试这个:
id是unic,不需要再设置它们了。
try this:
id is unic, dont neet to set any more them she.
您的代码中有很多错误(正如其他答案所指出的)。下面的代码说明了实现目标的正确方法。
HTML
JavaScript
这是一个工作小提琴。
You have quite a few mistakes in your code (as pointed out by the other answers). The code below illustrates the proper way to accomplish your goal.
HTML
JavaScript
Here's a working fiddle.