Js gets a checkbox to check whether it is selected. jscheckbox

Source: Internet
Author: User

Js gets a checkbox to check whether it is selected. jscheckbox

<Script language = javascript> function check () {var xz = document. getElementById ("xz"); alert (xz. checked) ;}</script> 

How can I use js to determine whether a check box is selected?

Var chk = document. getElementById ('checkbox id'); if (chk. checked) {// submit} else {// do not submit}

How does js obtain the tr of the selected checkbox line?

<Html>
<Head>
<Title> check box </title>
<Script type = "text/javascript">
Function del (){
Var tb = document. getElementById ("tb ");
If (tb. rows. length <2 ){
Return;
}
Var row;
Var cell;
Var chk;
// Less processing can be performed during iteration.
For (var I = tb. rows. length-1; I> 0; I --) {// If You Want To iterate the first line (I>-1)
Row = tb. rows [I]; // iterate the current row
Cell = row. cells [0]; // cell where the check box is located
Chk = cell. getElementsByTagName ("input") [0]; // indicates the number of INPUT elements in the cell.
If (chk. checked) {// if selected
Tb. deleteRow (I); // Delete and change rows
}
}
}
Var html;
Function reTB (){
Document. getElementById ("contentDiv"). innerHTML = html;
}
Window. onload = function (){
Html = document. getElementById ("contentDiv"). innerHTML;
}
</Script>
</Head>
<Body>
<Input type = "button" value = "delete selected row" onclick = "del ()"/>
<Input type = "button" value = "refresh" onclick = "reTB ()"/>
<Div id = "contentDiv">
<Table id = "tb" width = "250px" border = "1px">
<Tr> <td style = "width: 20%"> <input type = "checkbox"/> </td> <td style = "width: 40% "> name </td> <td &...... remaining full text>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.