0
    <script type="application/javascript">

    $(document).ready(function() {  
        $('input#newcommentinput').click(function() {
            $(this).hide();
            $(this).parent('.commentplaceofnewmodernpost').children('.newcommenttableinnewmodernpost').show();
            $('.textreaofnewcommentinnewmodernpost').focus(); 
        });
        $("input.postnewcomment").click(function() {
                var message=$(this).parent('.newcommenttableinnewmodernpost').children('.textreaofnewcommentinnewmodernpost').val();
                var post_id=$('.textreaofnewcommentinnewmodernpost').attr('id');
                alert(message);
                    if(message.length > 0){
                        $.post("PAGE_TO_POST", {comment:""+message+"",post_id:""+post_id+""}, function(data){
                            if(data.length >0) {
                                $('#newcommenthere').append(data);
                                $('table.newcommenttableinnewmodernpost').hide();
                                $('input.inputofnewcommentinnewmodernpost').show();
                                $('textarea.textreaofnewcommentinnewmodernpost').val('');
                                $('input.inputofnewcommentinnewmodernpost').val('Click to post comment...');
                            }
                        });}
        });

    });
</script>   

        <div class="commentplaceofnewmodernpost">
            <input class="inputofnewcommentinnewmodernpost watermarkpostcomment" id="newcommentinput">
            <table class="newcommenttableinnewmodernpost">
                <tr>
                    <td class="imgtdofnewcommenttable">
                        <img src=" IMG_ SRC" class="imgofdisplaycomment">
                    </td>
                    <td style="vertical-align:top;">
                        <textarea class="textreaofnewcommentinnewmodernpost watermarkpostcomment newcommenttextareaexpand" autocomplete="off" title="Click to post comment" id="POST_ID"></textarea>
                        <input type="button" class="greenbutton postsubmitbutton postnewcomment" value="Comment" title="Post comment" alt="Post comment" style="padding:5px 10px;margin-top:5px;" id="postnewcomment">
                        <input type="button" class="normalbutton postsubmitbutton" value="Cancel" title="Close to post comment" alt="Close to post comment" style="padding:5px 10px;margin:5px 0 0 15px;" id="cencalnewcomment">
                    </td>
                </tr>
           </table>
        </div>

这是我的 HTML 代码。当某些主体单击输入 id="newcommentinput" 然后隐藏此输入并在其后显示表格并在其后聚焦。并且当单击按钮 id="postnewcomment" 时,它将消息发布到另一个页面显示结果并隐藏表格并显示 previuos 输入。

如何用 jquery 做到这一点?

现在我正在使用上面的 jquery 代码来实现上面的语句......

请记住:页面中有多个 div,因此请写下您的答案以进行多选。

4

1 回答 1

1

这是将事件绑定到类的小代码...

也许你应该开始阅读 jquery 文档

    $(document).ready(function() {
            $(".inputofnewcommentinnewmodernpost").focusin(function() {
                    $(this).hide();
                    $(this).parent().find('.newcommenttableinnewmodernpost').show();
            });

            $('.postnewcomment').bind('click', function() {
                    $(this).parents('table').hide();
                    $(this).parents('.commentplaceofnewmodernpost').find('.inputofnewcommentinnewmodernpost').show();
            });
    });
于 2012-07-21T16:48:17.323 回答