Home >Web Front-end >JS Tutorial >jQuery select all/invert selection and click row to change background color example_jquery

jQuery select all/invert selection and click row to change background color example_jquery

WBOY
WBOYOriginal
2016-05-16 17:30:231192browse

I will put out the CSS style first. In fact, this can be ignored directly

Copy the code The code is as follows:

body{margin:0;padding:0;font-size:12px;font-family:Microsoft Yahei;}
.datagrid{width:100%;}
.datagird tr th{background-color: #191970; font-size:14px;}
.datagrid tr th, .datagrid tr td{border:1px solid #ccc; border-collapse:collapse;}
/* Select row style*/
.table-row-selected{background:#fff68f;}

Let’s look at the page HTML structure
Copy code The code is as follows:






< ;th>ID































Title Published by Published Time
1 What three things did Ali do right? Something? internet 2013- 07-01

2 Big inventory: 16 traditional industries rewritten by the Internet< /td>
internet 2013-07- 01
< ;/td>
3 What will Coolpad do if the smartphone market changes? internet 2013- 07-01

4 See how Ford resists Google and Apple? internet 2013- 07-01



Implement the function
1) Click the row to change the background color
Copy the code The code is as follows:

$ (".datagrid tbody tr").bind("click", function () {
var oThis = $(this);
if (oThis.hasClass("table-row-selected")) {
oThis.removeClass("table-row-selected");
oThis.children("td:eq(0)").children("input[name='check']").removeAttr("checked ");
} else {
oThis.addClass("table-row-selected");
oThis.children("td:eq(0)").children("input[name=' check']").attr("checked", "checked");
}
});

2) Select all/unselect all function (not completed, to be Continued)
Statement:
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