<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>jq之demo</title><!--线上jq库--><script src="https://code.jquery.com/jquery-3.4.1.min.js"></script><script src="1.js"></script> </head> <body> <h1>主页</h1> <table border="1"><tr><th>网站名</th><th>网址</th></tr><tr><td>百度</td><td>https://www.baidu.com/?tn=40020637_4_oem_dg</td></tr><tr><td>b站</td><td>https://www.bilibili.com/</td></tr><tr><td>csdn</td><td><a href="https://blog.csdn.net/wanggang182007">无名csdn</a></td></tr><tr><td>github</td><td>https://github.com/trending/java?since=monthly</td></tr><tr><td>gitee</td><td>https://search.gitee.com/?skin=rec&type=repository&q=%E7%94%B5%E5%95%86</td></tr> </table> <button>点我<button/> </body> </html>
$(document).ready(function(){$("button").click(function(){/*$("tr:odd")奇数位置的tr元素*/$("tr:odd").css("background-color","red");}); });