對于一個表格,為了使我們選中的項更容易區分,需要為選中項添加高亮,同時也需要,將其他項的高亮形式去除。類似于:
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head><meta charset="utf-8" /><title></title><link href="css/style.css" rel="stylesheet" type="text/css" /><script src="jquery-1.3.2.min.js"></script><script>$(function () {$('tbody>tr').click(function () {$(this).addClass('selected') //為選中項添加高亮.siblings().removeClass('selected')//去除其他項的高亮形式.end();});}); </script></head><body><table><thead><tr><th>姓名</th><th>性別</th><th>暫住地</th></tr></thead><tbody><tr><td>張三</td><td>男</td><td>浙江寧波</td></tr><tr><td>張三</td><td>男</td><td>浙江寧波</td></tr><tr><td>張三</td><td>男</td><td>浙江寧波</td></tr><tr><td>張三</td><td>男</td><td>浙江寧波</td></tr><tr><td>張三</td><td>男</td><td>浙江寧波</td></tr></tbody></table></body></html>
以上內容是小編給大家介紹的jQuery代碼實現表格中點擊相應行變色功能的全部內容,希望對大家有所幫助!
新聞熱點
疑難解答