在页面加载时,我有两个div块“replyComment”和“tobereplaced”
<div id="replyComment">
<form id="myForm" name="myForm" method="post" action="reply.php" >
<textarea name="suggestions" rows="5" cols="60" style="resize:none" onfocus="this.value=''">Enter your reply here</textarea>
<input type="hidden" name="hidden">
<input type="hidden" name="hidden2" >
<a href="blog.php?page=hm"><img src="html_images/cancel.png" onmouseover="src='html_images/cancelhover.png'" onmouseout="src='html_images/cancel.png'" alt="Cancel"/></a>
<input type="image" name="Post" value="Reply" alt="Reply" src="html_images/reply.png" onmouseover="src='html_images/replyhover.png'" onmouseout="src='html_images/reply.png'"/>
</form>
</div>
<div name="tobereplaced">
<img src="html_images/reply.png" class="ajax-func" onmouseover="src='html_images/replyhover.png'" onmouseout="src='html_images/reply.png'" />
</div>
我试图在加载时隐藏replyComment div并将其切换为在点击下面显示以下jquery。
$(document).ready(function () {
$(".replyComment").hide();
$(".ajax-func").click(function(evt) {
$(this).prevAll(".replyComment:first").slideToggle("fast");
$(this).toggleClass("active");
return false;
});
});
但是replyComment没有隐藏在页面加载上也没有切换..我是jquery的新手,任何帮助都将不胜感激..
答案 0 :(得分:3)
如果您通过类引用元素并使用哈希选择器按ID引用元素,则使用点选择器。 所以在你的情况下,你应该:
$('#replyComment').hide();
答案 1 :(得分:1)
您的div是id
,但您的选择器正在寻找课程。试试这个:
$("#replyComment").hide();
答案 2 :(得分:0)
你的选择器错了。 “.replyComment”将标记与replyComment类匹配。
对于id,你应该选择“#replyComment”。
尝试学习更多选择器,它们是jQuery的灵魂,并浏览http://jqapi.com/以供参考。