<!DOCTYPE html>
<html>
<head>
<title>HTML jQuery Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").toggle();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Toggle paragraphs</button>
</body>
</html>
HTML结构:
<h2>), 两个段落 (<p>), 和一个按钮 (<button>).jQuery库引入:
<script>标签从CDN加载jQuery库 (https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js)。jQuery代码:
$(document).ready(function(){ ... }); 确保DOM完全加载后再执行代码。$("button").click(function(){ ... }); 绑定点击事件到按钮上。$("p").toggle(); 切换所有段落的显示状态(隐藏或显示)。功能描述:
上一篇:html中margin的用法
下一篇:html 框架
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站