jquery - 在 div 内显示表单 onclick

标签 jquery

感谢您的阅读。

我有评论列表,每个评论都有一个回复链接。当您单击链接时,应显示该单独评论的表单。

我很困惑。我写了这个 jquery,但我知道它根本没有意义。

  <script>
     $('.reply-comment').click(function(){

    var CommentID = $(this).attr('id');

    $(this).hide();
    $('.reply-comment-form').show( function(){
        $('.reply-comment-form-'+CommentID).html();
    });

    return false;
});
</script>

这是表格

    <div class="reply-comment-form well">';
     <form name="reply-form" id="reply-form" method="POST">
      <textarea name="Comment" rows="6" class="span10"></textarea> <br />
      <input type="submit" class="btn btn-primary replycommentsubmitbutton" value="Yanitla" />
     </form>
    </div> 

我在每个评论下添加了一个跨度以供表单显示

<div>
      comments text etc etc...
</div>
   <a href="" class="reply-comment" id="<?php $v['CommentID'] ?>"> Reply </a>
   <span id="reply-fomment-form-<?php $v['CommentsID'] ?>"></span>

那么,如何将 show() 函数与 html() 函数一起使用,或者还有其他方法吗?

你能帮我一下吗?谢谢。

最佳答案

例如,生成所有表单并隐藏这些表单

HTML:

<div>comments text etc etc...</div>
<a href="" class="reply-comment" id="<?php $v['CommentID'] ?>"> Reply </a>
<form class="reply-form">
    <input />
    <input type="submit" />
</form>
<br />
<div>comments text etc etc...</div>
<a href="" class="reply-comment" id="<?php $v['CommentID'] ?>"> Reply </a>
<form class="reply-form">
    <input />
    <input type="submit" />
</form>

CSS:

.reply-form{ display:none; }

JS:

$(function(){
    $('.reply-comment').on('click', function(e){
        e.preventDefault();
        $(this).next('.reply-form').show();
    });
});

DEMO. Updated Demo using OP's markup.

关于jquery - 在 div 内显示表单 onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18904298/

相关文章:

jquery - 动态替换对话框按钮文本

jquery - 显示隐藏表格行

javascript - ckeditor LINK 在 jQuery 对话框中不起作用

jquery - 检测是否显示 div - 差异与空 div?

javascript - 如何在右键单击表格行时显示编辑按钮

javascript - Bootstrap 中带有选项卡的链接下拉菜单

javascript - 从 cookie 加载 CSS 类(带有转换),而不转换到它们中

ajax - jQuery过滤AJAX数据然后replaceWith数据

javascript - var 上的 "+"字符出现问题

Javascript格式float中的小数位数