单击隐藏按钮,矩形将被隐藏起来
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>隐藏矩形</title> <script type="text/javascript" src="jquery-3.3.1.js"></script> <style type="text/css"> div{ width: 200px; height: 200px; background: pink; border: 1px solid #ccc; } </style> </head> <body> <div></div> <button>隐藏</button> <script type="text/javascript"> //文本就绪 $(document).ready(function(){ $('button').click(function(){ $('div').hide() }) }) </script> </body> </html>
总结:
1、需要在头文件中引入jQuery文件
2、需要在变成功能之前写文档就绪函数:$(document).ready(function(){
内容}),然后再在内容部分写功能代码