简体   繁体   English

Jquery多次显示隐藏

[英]Jquery show hide multiple times

I have a comment tree similar to Reddit's.我有一个类似于 Reddit 的评论树。 People will need to be able to reply the comments by clicking a reply link, and then a form with a textarea should come.人们需要能够通过单击回复链接来回复评论,然后应该会出现一个带有 textarea 的表单。 I tried using the .show() method, but there is more than one comment, and when you click reply it shows all the forms for every comment.我尝试使用.show()方法,但有不止一条评论,当您单击回复时,它会显示每条评论的所有表单。 How can i fix this?我怎样才能解决这个问题? What should i look into?我应该看什么?

  1. You'll need to set a class for each textarea (A different class for each one).您需要为每个textarea设置一个类(每个都有一个不同的类)。 Let's say:让我们说:

    <textarea class="commentAnswerBox1">Answer here...</textarea>

  2. Now you have to set up a class for each comment answer button Like this现在你必须为每个评论回答按钮设置一个类像这样

    <input type="button" class="btnAnswer1" value="Answer this comment" />

  3. Now you can call a function that recognizes which btnAnswer was clicked, and show only the correspondent commentBox .现在您可以调用一个函数来识别点击了哪个btnAnswer ,并且只显示相应的commentBox

You can use Class or IDs, or also create an attribute, it doesn't matter.您可以使用 Class 或 ID,也可以创建一个属性,这无关紧要。

It seems to me that the issue stems from your DOM selector.在我看来,问题源于您的 DOM 选择器。 It looks like you want to only show the last text area.看起来您只想显示最后一个文本区域。 If this is the case then you want something like如果是这种情况,那么你想要类似的东西

$('textarea:last').show();

Post more info so we can provide better answers.发布更多信息,以便我们提供更好的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM