Php jQuery-单击链接/按钮时显示文本框

Php jQuery-单击链接/按钮时显示文本框,php,javascript,jquery,textarea,Php,Javascript,Jquery,Textarea,我试图为每条评论设置一个回复按钮,这样当有人点击按钮(例如“回复”)时,就会自动弹出一个文本框,用户可以在其中填写表单 到目前为止我没做什么 PHP 回复 jQuery 函数jsReply(注释\u id){ var形式=“”; form+='我建议使用jQuery库 通过CSS隐藏#showreply显示:无;并将HTML表单放在其中 $('#replycomment').click(function() { $('#showreply').show(); }); 我还建议将ID更

我试图为每条评论设置一个回复按钮,这样当有人点击按钮(例如“回复”)时,就会自动弹出一个文本框,用户可以在其中填写表单

到目前为止我没做什么

PHP
回复
jQuery
函数jsReply(注释\u id){
var形式=“”;

form+='我建议使用jQuery库

通过CSS隐藏
#showreply
显示:无;
并将HTML表单放在其中

$('#replycomment').click(function() {
    $('#showreply').show();
});

我还建议将ID更改为类,因为您将有多个实例。

我建议使用jQuery库

通过CSS隐藏
#showreply
显示:无;并将HTML表单放在其中

$('#replycomment').click(function() {
    $('#showreply').show();
});
我还建议将ID更改为类,因为您将有多个实例。

PHP

<div class='reply'>Reply</div>
<form action='add_reply.php' method='POST' class='reply-form'>
  <textarea name='replybody'></textarea>
  <input type='hidden' name='comment_id' value='<?php echo $comment_id; ?>' />
  <input type='submit' value='Reply' />
</form>
Javascript

$(".reply").click(function() {
  $(this).siblings(".reply-form").show();
  $(this).hide();
});
PHP

<div class='reply'>Reply</div>
<form action='add_reply.php' method='POST' class='reply-form'>
  <textarea name='replybody'></textarea>
  <input type='hidden' name='comment_id' value='<?php echo $comment_id; ?>' />
  <input type='submit' value='Reply' />
</form>
Javascript

$(".reply").click(function() {
  $(this).siblings(".reply-form").show();
  $(this).hide();
});

要使代码正常工作,请执行以下操作:

头部内:

var jsReply = function(comment_id) {
    var form = '<form id="showReplyForm" action"add_reply.php" method="post">';
    form += '<textarea name="replybody" cols="35" rows="2" maxlength="299"></textarea>';
    form += '<input type="hidden" name="replybodyId" value="' + comment_id + '" />';
    form += '<input type="submit" name="replysubmit" value="Reply"/></form>';
    jQuery('#showreply').replaceWith(form);
}
var jsReply=函数(注释id){
var形式=“”;
形式+='';
形式+='';
形式+='';
jQuery('#showreply')。替换为(表单);
}
您在一个表单连接的末尾缺少一个半冒号。您查看的是“replyBody”而不是html中存在的“showreply”,并且如果您的代码不是全局html,则不会为onclick定义它。您还缺少开头textarea标记的结束角括号


另外,我不知道您的上下文,我不是来这里查看代码的,但除其他几件事外……您应该真正避免在html元素中使用
onclick

要使代码正常工作,请执行以下操作:

头部内:

var jsReply = function(comment_id) {
    var form = '<form id="showReplyForm" action"add_reply.php" method="post">';
    form += '<textarea name="replybody" cols="35" rows="2" maxlength="299"></textarea>';
    form += '<input type="hidden" name="replybodyId" value="' + comment_id + '" />';
    form += '<input type="submit" name="replysubmit" value="Reply"/></form>';
    jQuery('#showreply').replaceWith(form);
}
var jsReply=函数(注释id){
var形式=“”;
形式+='';
形式+='';
形式+='';
jQuery('#showreply')。替换为(表单);
}
您在一个表单连接的末尾缺少一个半冒号。您查看的是“replyBody”而不是html中存在的“showreply”,并且如果您的代码不是全局html,则不会为onclick定义它。您还缺少开头textarea标记的结束角括号

另外,我不知道您的上下文,我也不是来这里查看代码的,但除此之外,您应该避免在html元素中使用
onclick