javascript - Javascript foreach循环?
问题描述
我对 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 代码只适用于一行,因为我自己分配了 id,就像在 JS 和中继器中一样。但是在第二行之后,ID 会自动更改为中继器计数器之类的东西。
所以我真正的问题是,除了在脚本中使用相同的 ID 进行编辑之外,我如何在转发器中编辑我的行,它们将具有不同的 ID。我想我需要使用 foreach() 但不知道该怎么做。
当我只输入他们的类“.editable”或者我可以创建另一个类时,我希望我的所有行都可以编辑,这并不重要。我想要的只是一个无 ID 的解决方案。
解决方案
我无法在代码段中运行您的代码。Bu尝试使用$('.editable')
而不是 id $('#rptQuestionTitle')
。如果插件准备好接收一个数组并使用它,它就会工作。
推荐阅读
- javascript - 如何从传递给其兄弟组件的下拉框中获取 ref 值?
- assembly - RISC-V:PC 绝对值与 PC 相对值
- java - 线程“main”中的异常 java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version
- python - django比较时间字段
- sql - 新手 SQL 学习者(内连接)
- python - 元组中的字符串和整数值
- php - JSON:从另一个域检索 JSON 文件
- java - 如何在 Spark 任务执行器工作时将多个 json 对象存储在 Java 并发 Java 列表中
- linkedin - LinkedIn公司关注按钮不起作用
- javascript - 使用 Mustache 循环 json