Javascript foreach循环?

时间:2019-07-17 14:48:34

标签: javascript jquery html asp.net repeater

我对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>

我正在尝试创建可编辑的表格。我必须能够编辑每一行。但是如您所见,我的脚本代码只能分配ID为可编辑状态。我需要让课程可编辑。 在ASP.NET转发器中,由于转发器,每个元素都具有不同的ID。我的编辑JS代码仅适用于一行,因为像JS和Repeater一样,我自己分配了ID。 但是,在第二行之后,ID会自动更改为类似中继器的计数器。

所以我真正的问题是,除了在脚本中用相同的ID进行编辑外,我该如何在中继器中编辑具有不同ID的行。我想我需要使用foreach(),但不确定如何去做。

我只想在我的类输入“ .editable”时就使所有行都可编辑,否则我可以创建另一个类,这没关系。我想要的是一个无ID的解决方案。

1 个答案:

答案 0 :(得分:0)

我无法在代码段中运行您的代码。请尝试使用$('.editable')代替ID $('#rptQuestionTitle')。如果插件准备好接收数组并可以使用它,那么它将起作用。