Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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 如何通过Jquery添加rails html标记?_Javascript_Jquery_Ruby On Rails_Ruby On Rails 5 - Fatal编程技术网

Javascript 如何通过Jquery添加rails html标记?

Javascript 如何通过Jquery添加rails html标记?,javascript,jquery,ruby-on-rails,ruby-on-rails-5,Javascript,Jquery,Ruby On Rails,Ruby On Rails 5,我试图使用jquery添加rails html代码,但没有成功。 我尝试过的代码: <% @user.each do |record| %> <tr> <td> <%= record.name %> </td> <td> <%= record.gender %> </td>

我试图使用jquery添加rails html代码,但没有成功。 我尝试过的代码:

   <% @user.each do |record| %>    
      <tr>
       <td>
         <%=  record.name %> 
       </td>
       <td>
         <%= record.gender %>
       </td>
      <%= record.dob %>
       </td>
    </tr>
  <% end %>
 <button id="edit_button" class="btn btn-primary btn-sm edit" onclick="editRow();">更新</button>
  

  function editrow(){
     var $item = $('.edit').closest("tr").find(".nr");
         var name = "<%= text_field 'name', class: 'form-control' %>"
         $item[0].innerHTML= name;
   } 

更新
函数editrow(){
变量$item=$('.edit')。最近的(“tr”)。查找(“.nr”);
var name=“”
$item[0]。innerHTML=name;
} 
但它并没有给出错误,比如名称是未定义的方法。
也尝试使用不同的,但旧值未显示。

您无法动态插入ERB标记。 呈现ERB的顺序如下所示:

Rails reads ERB and renders HTML+assets -> 
HTML+assets get returned to your browser -> 
Your browser renders HTML and executes JavaScript
您的浏览器无法读取ERB:(


你能再告诉我们一点你想用“编辑行”做什么吗函数,以及向我们显示更多的ERB?

onclick
editRow
函数使输入字段在行中,并在输入中显示旧值。@vvp45如何呈现原始值和
?单击编辑按钮时,只需切换css类名以隐藏/显示元素。