我有一個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個元素 –