使用jeditable可以同时编辑所有字段

时间:2013-01-14 08:33:03

标签: jquery ruby-on-rails ruby-on-rails-3 jeditable

我正在Ruby on Rails中使用jeditable。

我要做的就是点击一个按钮,某一行的所有字段都可以编辑,并自动进入可编辑状态。这可能吗?

这是我的java脚本

<script>
jQuery(document).ready(function($) {
    $(".edit_textfield").each( function() {  
          $(this).editable('<%= @student.id%>', {
                indicator   :'Saving...',
                tooltip     :'Click to edit...',
                rows        :10,
                method      :"PUT",
                submitdata: {id: $(this).attr('id'),name: $(this).attr('name')}
            });
    });
});
</script>

这是展示页

<p>
  <b><%=t :Name%>:</b>
  <dd class="edit_textfield" id="<%= @student.id %>" name="name"><%= @student.name %></dd>
</p>

<p>
  <b><%=t :Age%>:</b>
  <dd class="edit_textfield" id="<%= @student.id %>" name="age"><%= @student.age %></dd>
</p>

<p>
  <b><%=t :Address%>:</b>
  <dd class="edit_textfield" id="<%= @student.id %>" name="address"><%= @student.address %></dd>
</p>

<p>
  <b><%=t :Phone%>:</b>
  <dd class="edit_textfield" id="<%= @student.id %>" name="phone"><%= @student.phone %></dd>
</p>

我想设置一个像

这样的按钮
<button type="button" id="button1">Click this button and all the fields will become editable!</button>

这样点击这个我想让所有字段都可编辑

1 个答案:

答案 0 :(得分:4)

的javascript

$(".edit_trigger").bind("click", function() {
    $(".edit_textfield").click();
});

按钮

<button type="button" class="edit_trigger">Click this button and all the fields will become editable!</button>
相关问题