Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Rail的原型助手形成显示/隐藏效果_Javascript_Ruby On Rails_Ruby_Forms_Prototype - Fatal编程技术网

Javascript 使用Rail的原型助手形成显示/隐藏效果

Javascript 使用Rail的原型助手形成显示/隐藏效果,javascript,ruby-on-rails,ruby,forms,prototype,Javascript,Ruby On Rails,Ruby,Forms,Prototype,我正在尝试创建一个线程评论系统,它的行为类似于Reddit:我点击评论上的回复,就会出现一个表单。此表单有一个“取消”按钮,用于删除表单,并返回到原始状态 我试图通过一个link-to-u函数添加表单来实现这一点,表单本身有一个按钮-to-u函数来移除自身和表单。因此,由link_to_函数生成的javascript需要包含转义HTML和转义javascript,并且由于某些原因,它无法工作,单击Reply不起任何作用。如果我不添加“取消”按钮,它可以正常工作。以下是我所拥有的: <!--

我正在尝试创建一个线程评论系统,它的行为类似于Reddit:我点击评论上的回复,就会出现一个表单。此表单有一个“取消”按钮,用于删除表单,并返回到原始状态

我试图通过一个link-to-u函数添加表单来实现这一点,表单本身有一个按钮-to-u函数来移除自身和表单。因此,由link_to_函数生成的javascript需要包含转义HTML和转义javascript,并且由于某些原因,它无法工作,单击Reply不起任何作用。如果我不添加“取消”按钮,它可以正常工作。以下是我所拥有的:

<!-- comments/_comment.html.erb -->
<div id="comment_<%= comment.id %>">
  <%= h comment.content %>
</div>

<div id="reply_comment_<%= comment.id %>"></div>

<%= link_to_function 'Reply' do |page|
      page.replace_html "reply_comment_#{comment.id}",
        render(:partial => 'comments/form', :locals => {:comment => comment,
               :commentable => comment.commentable})
    end
%>
以及:


我做错了什么?

虽然这在技术上可以完全按照您指定的方式进行,但我认为编码中存在错误,因为JavaScript中包含JavaScript。我敢肯定,在那里的某个地方有一个悠悠的笑话。内部JavaScript的第二位可能没有正确引用

您可以不使用replace_html函数,只需将partial设置为hidden,然后关闭和打开可见性

或者,您可以尝试通过任何必要的方式修复编码


我只是在这里假设。如果您可以发布这篇文章的输出,那么就更容易确定了。

我不确定您正在做的事情不起作用的确切原因,但这里有一种替代方法来做您正在尝试做的事情。不需要在DIV中插入和删除文本,只需在元素上显示/隐藏我删除了表单内容,但格式大致相同:

<!-- comments/_form.html.erb -->
   <%= button_to_function 'Cancel', "$('reply_comment_blah').hide()" %>
</p>

<!-- comments/_comment.html.erb -->
<div id="comment_blah">
  Hello!
</div>

<div id="reply_comment_blah", style="display: none;"><%= render :partial => 'form' %></div>

<%= link_to_function 'Reply' , "$('reply_comment_blah').show()" %>
<!-- comments/_form.html.erb -->
   <%= button_to_function 'Cancel', "$('reply_comment_blah').hide()" %>
</p>

<!-- comments/_comment.html.erb -->
<div id="comment_blah">
  Hello!
</div>

<div id="reply_comment_blah", style="display: none;"><%= render :partial => 'form' %></div>

<%= link_to_function 'Reply' , "$('reply_comment_blah').show()" %>