Home > Web Front-end > HTML Tutorial > The first column in the dynamically generated HTML Table is checkbox. How to determine which checkboxes are selected and obtain the corresponding record_html/css_WEB-ITnose

The first column in the dynamically generated HTML Table is checkbox. How to determine which checkboxes are selected and obtain the corresponding record_html/css_WEB-ITnose

PHP中文网
Release: 2016-06-24 12:08:17
Original
1445 people have browsed it

The first column in the table of dynamically generated HTML is checkbox. How to determine which checkbox is selected and obtain the corresponding record? ?


js code:

function get(){
var print = document.getElementsByName("isprint");
for(var i = 0; i < print.length; i++) {
if(print[i].checked) {
var factorId = document.getElementById(&#39;factorId&#39;).value;
alert(factorId);
} 
}
}

<table class="grid">
<tfoot></tfoot> 
<tbody>
<tr>
<th width="30px" >序号</th>
<th>标签要素名称</th>            
<th>是否起用</th>     
</tr>
<s:iterator value="%{pageDataFactorDef.datals}" id=&#39;vo&#39; status=&#39;st&#39;>
<td align="center"><s:property value="#st.count+(pageDataFactorDef.currentPage-1) * 
(pageDataFactorDef.pageSize)" /></td>
<td>${vo.factorName}</td>
<td>
<input type="checkbox" name="isprint" id="isprint" />
</td>
<td align="center"> <input id="factorId" value="${vo.factorId}" type="hidden"></input>//  取得隐藏域id值
   
 </tr> 
</s:iterator>       
</tbody>
</table>
Copy after login

The id obtained in js is always the first record in the table, no matter what you select For several pieces of data, it all displays the id value of the first record data.


Reply to discussion (solution)

The ids of all your hidden fields are the same. Of course, take the first one

Then how to get the data corresponding to the selected

<input type="checkbox" name="isprint" id="isprint" cmdValue="${vo.factorId}" />
if(print[i].checked) {
alert(print[i].getAttribute("cmdValue"));
}
Copy after login
<input type="checkbox" name="isprint" id="isprint" />
Copy after login

and change it to

<input type="checkbox" name="isprint<%# Container.ItemIndex+1 %>" id="isprint<%# Container.ItemIndex+1 %>" />
Copy after login

and add an ID

JS Search the number of rows of

var rowCount = document.all.tbodyDetail.children.length - 1;
for (var i = 1; i <= rowCount; i++) {
var checkbox= form1["checkbox" + i].value.trim();
}
Copy after login

and then you traverse the rowCount
and you can get the checkbox id

The above is the dynamically generated html table. One column is checkbox. How to determine which checkbox is selected and obtain the corresponding record_html/css_WEB-ITnose content. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template