2013-01-14 60 views
3

我正在Ruby on Rails中使用jeditable。所有字段在同一時間使用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> 

以便通過點擊此我想一個按鈕使所有字段都可編輯

回答

4

Java腳本

$(".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>