0

ページの読み込み時に、「replyComment」と「tobereplaced」の 2 つの div ブロックがあります。

<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

divはですidが、セレクターはクラスを探しています。これを試して:

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

セレクターが間違っています。「.replyComment」は、タグをクラスreplyCommentと一致させます。

IDには、セレクター「#replyComment」を選択します。

もう少しセレクターを調べてみてください。それらはjQueryの魂であり、http://jqapi.com/を参照して参照してください。

于 2012-05-18T20:54:03.173 に答える