表格选中TR,自动勾选CHECKBOX的方法

WBOY
Release: 2016-06-23 14:00:22
Original
1875 people have browsed it

  大家好,我碰到这样一个问题

  我有一个TABLE,我希望单击这个TABLE的某一行的任意位置,则这个TABLE前面的CHECKBOX能够被选中,并且该行背景颜色改变,反之取消勾选


回复讨论(解决方案)

绑定tr的click事件。
动态修改tr的css类。
同时修改checkbox的选中状态

给个例子参考吧

 <style> .selected {    background-color: red;} </style> <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> <script> $(function(){ $('#data tr').on('click', function() {    $(this).toggleClass('selected');	var checkBoxe = $(this).find("input");	checkBoxe.prop("checked", !checkBoxe.prop("checked"));}); });</script><table id='data'><tr><td><input type="checkbox" value="1"></td><td>eeeeeeeeeee</td></tr><tr><td><input type="checkbox" value=""></td><td>fffffffffff</td></tr><tr><td><input type="checkbox" value=""></td><td>ggggggggggg</td></tr></table>
Copy after login

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!