Javascript foreach 循环?

Javascript foreach loop?

我对 asp.net 中的转发器对象有疑问。

在 html 和脚本部分我有下面的代码。

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(MyEdit);

function MyEdit() {
  jQuery(function($) {

    //editables on first profile page
    $.fn.editable.defaults.mode = 'inline';
    $.fn.editableform.loading = "<div class='editableform-loading'><i class='ace-icon fa fa-spinner fa-spin fa-2x light-blue'></i></div>";
    $.fn.editableform.buttons = '<button type="submit" class="btn btn-info editable-submit"><i class="ace-icon fa fa-check"></i></button>' +
      '<button type="button" class="btn editable-cancel"><i class="ace-icon fa fa-times"></i></button>'
    //editables 
    //text editable
    $('#rptQuestionTitle')
      .editable({
        type: 'text',
        name: 'username'
      });
    $('#rptQuestionDescription')
      .editable({
        type: 'text',
        name: 'username'
      });

  });
}
MyEdit();
<asp:Repeater ID="rptQuestionRepeater" runat="server">
  <HeaderTemplate>
    <table class="table table-bordered">
      <tr>
        <th style="width: 50px">No</th>
        <th style="width: 200px; height: auto">Question</th>
        <th style="width: 400px; height: auto">Description</th>
      </tr>
  </HeaderTemplate>
  <ItemTemplate>
    <tr>
      <td>
        <%#Eval("Sort")%>
      </td>
      <td><span class="editable editable-click" runat="server" id="rptQuestionTitle"><%#Eval("Text") %></span></td>
      <td><span class="editable editable-click" runat="server" id="rptQuestionDescription"><%#Eval("Description") %></span></td>
    </tr>
  </ItemTemplate>
  <FooterTemplate>
    </table>
  </FooterTemplate>
</asp:Repeater>

我正在尝试做一个 editabletable。我必须能够编辑每一行。但是你可以看到我的脚本代码,我只能将 id 指定为 editable。我需要 class editable。 在 ASP.NET 转发器中,由于转发器,每个元素都有不同的 ID。我的编辑 JS 代码仅适用于一行,因为我已经像在 JS 和 Repeater 中一样自行分配了 id。 但在第二行之后,ID 会自动更改为中继器计数器之类的东西。

所以我真正的问题是,除了在脚本中使用相同的 ID 进行编辑之外,我如何在转发器中编辑我的行,它们将具有不同的 ID。我想我需要使用 foreach() 但不知道该怎么做。

我想要我的所有行 editable 当我只输入它们的 class ".editable" 或者我可以创建另一个 class 时,它不会真的很重要。我想要的只是一个免ID的解决方案。

我无法 运行 您的代码片段。请尝试使用 $('.editable') 而不是 ID $('#rptQuestionTitle')。如果插件准备好接收数组并使用它,它就会工作。