我有一个HTML的结构是这样的: -如何使用jQuery选择工作
<article id="a_post" class="a_post">
<div id="thumbnail">
<img id="shine" src="wp-content/themes/dabanggknight/images/play.png"/>
</div>
<div id="instant_video" class="instant_video">
<span class="close"></span>
// Some content here
</div>
</article>
<article id="a_post" class="a_post">
<div id="thumbnail">
<img id="shine" src="wp-content/themes/dabanggknight/images/play.png"/>
</div>
<div id="instant_video" class="instant_video">
<span class="close"></span>
// Some content here
</div>
</article>
在上面的HTML,<div id="instant_video" class="instant_video"> <span class="close"></span> // Some content here </div>
有display:none;
一个css。 我想要做的就是当有人点击<img id="shine" src="wp-content/themes/dabanggknight/images/play.png"/>
我想滑下div的id为instant_video,其显示在css中设置为none。
然后,当有人点击关闭类的跨度时,它会再次淡出该特定的div。
但我遇到了jQuery选择器的严重问题,因为我真的是业余爱好者。
我正在使用的代码在所有隐藏的div中滑动,其id为instant_video
,这就是问题持续存在的地方。
我想要做的只是向下滑动文章标签中包含我点击的图像的div。
我目前使用的代码如下: -
jQuery(document).ready(function() {
jQuery('img#shine').click(function() {
jQuery('.instant_video').slideDown('fast')
});
});
jQuery(document).ready(function() {
jQuery('.close').click(function() {
jQuery('.instant_video').fadeOut('slow')
});
});
首先使用'$'代替'jQuery' - 只需更短一点,然后使用'$(document).ready(function()...'每页只有一次 –
我的建议:不要使用相同的名称对于一个班级和身份证号码,永远不要给同一个ID超过1个元素 –