【发布时间】:2016-03-29 17:57:54
【问题描述】:
我有一个带有表格的 ASP.NET (4.5) 页面,表格的每一行都有几个字段和一个复选框,我已经有一个 java 函数来确定选中哪些复选框并返回该信息返回 vb.net 代码以通过隐藏字段进行处理。我现在需要能够将表中另一个字段的值与选中的复选框 ID 一起发送回来,我不知道如何。
所以我正在寻找我的隐藏字段最终看起来像:
chkboxID1,otherfield1,chkboxID2,otherfield2,..等
我当前的代码是:
<script>
function test() {
var idSelector = function () { return this.id; };
var bChecked = $(":checkbox:checked").map(idSelector).get();
document.getElementById('<%=shortlists.ClientID%>').value = bChecked;
}
</script>
<input id="clickMe" type="submit" value="Shortlist" onclick="test();" />
<asp:HiddenField ID="shortlists" runat="server" />
我要从中提取数据的表是:
<table id="shortlist" class="compact" style="text-align: center;">
<thead style="text-align: center">
<tr>
<th colspan="3" style="text-align: center">Details</th>
<th colspan="4" style="text-align: center">Stats</th>
<th colspan="3" style="text-align: center">Overall</th>
</tr>
<tr>
<th style="text-align: center">Date/Time</th>
<th style="text-align: center">League</th>
<th style="text-align: center">Fixture</th>
<th style="text-align: center">P</th>
<th style="text-align: center">ALL</th>
<th style="text-align: center">L2</th>
<th style="text-align: center">LP +-2</th>
<th style="text-align: center">Avg FHG</th>
<th style="text-align: center">Rating</th>
<th style="text-align: center">Checkbox</th>
</tr>
</thead>
<tbody>
<tr>
<td>23/12/2015 19:30:00</td>
<td>Serie B</td>
<td>Pescara v Modena</td>
<td>18</td>
<td>44.44</td>
<td>25</td>
<td>33.33</td>
<td>2.56</td>
<td>34</td>
<td><input id=357701 type="checkbox" />
</td>
</tr>
<tr>
<td>23/12/2015 19:30:00</td>
<td>Serie B</td>
<td>Pro Vercelli v Perugia</td>
<td>19</td>
<td>31.58</td>
<td>50</td>
<td>25</td>
<td>1.84</td>
<td>36</td>
<td><input id=357702 type="checkbox" /></td>
</tr>
</tbody>
</table>
我想获取所选复选框的 ID 和“评级”列的值,所以从这个例子中(假设两个复选框都打勾)我希望我的隐藏字段读取:
357701,34,35702,36
【问题讨论】:
-
你可以用ajax,json来做
-
除了处理提交的输入之外,还有什么理由处理js填充的隐藏字段?
标签: javascript jquery asp.net