0

在页面加载时,我有两个 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的新手,任何帮助将不胜感激..

4

3 回答 3

3

如果您通过类引用元素,则使用点选择器,使用哈希选择器通过 ID 引用元素。所以在你的情况下,你应该有:

$('#replyComment').hide(); 
于 2012-05-18T20:52:41.817 回答
1

Your div is an id, but your selector is looking for classes. Try this:

 $("#replyComment").hide();
于 2012-05-18T20:53:04.393 回答
0

Your selector is wrong. ".replyComment" matches a tag with the class replyComment.

For the id you sould the selector "#replyComment".

Try studing a little bit more selectors, they are the soul of jQuery and browse http://jqapi.com/ for references.

于 2012-05-18T20:54:03.173 回答