当前位置: 首页 > wzjs >正文

怎么做网站关键词推广日本关键词热搜榜

怎么做网站关键词推广,日本关键词热搜榜,58同城网招聘,什么是网络营销的重要组成部分jQuery 单击页面显示自定义动画、元素删除操作、随机抽奖、随机选图并放大语法知识点 1. jQuery 基础语法 1.1 引入 jQuery 在使用 jQuery 之前&#xff0c;需要先引入 jQuery 库。可以通过 CDN 引入&#xff0c;也可以下载到本地使用。 <!-- 通过 CDN 引入 jQuery -->…

jQuery 单击页面显示自定义动画、元素删除操作、随机抽奖、随机选图并放大语法知识点


1. jQuery 基础语法

1.1 引入 jQuery

在使用 jQuery 之前,需要先引入 jQuery 库。可以通过 CDN 引入,也可以下载到本地使用。

<!-- 通过 CDN 引入 jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

1.2 基本语法结构

jQuery 的基本语法结构为:

$(selector).action();
  • $ 符号:定义 jQuery。
  • selector:选择器,用于选取 HTML 元素。
  • action():对选取的元素执行的操作。

1.3 文档就绪函数

确保在 DOM 完全加载后再执行 jQuery 代码。

$(document).ready(function(){// jQuery 代码
});

或使用简写:

$(function(){// jQuery 代码
});

2. 单击事件处理

2.1 .click() 方法

用于为元素绑定单击事件。

$("button").click(function(){alert("按钮被点击了!");
});

2.2 .on() 方法

更灵活的事件绑定方式,支持多个事件。

$("button").on("click", function(){alert("按钮被点击了!");
});

2.3 示例

<!DOCTYPE html>
<html>
<head><title>jQuery 单击事件示例</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><script>$(document).ready(function(){$("button").click(function(){$("p").text("按钮被点击了!");});});</script>
</head>
<body><button>点击我</button><p>等待点击...</p>
</body>
</html>

3. 动态显示/隐藏元素

3.1 .show().hide() 方法

用于显示和隐藏选定的元素。

$("button").click(function(){$("p").toggle(); // 切换显示/隐藏
});

3.2 .toggle() 方法

切换元素的显示和隐藏状态。

3.3 示例

<!DOCTYPE html>
<html>
<head><title>显示/隐藏元素示例</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><script>$(document).ready(function(){$("#toggleBtn").click(function(){$("#toggleText").toggle();});});</script>
</head>
<body><button id="toggleBtn">切换显示/隐藏</button><p id="toggleText">这是一个可切换显示的段落。</p>
</body>
</html>

4. 自定义动画

4.1 .animate() 方法

用于创建自定义动画效果。

$("button").click(function(){$("div").animate({left: '250px',opacity: '0.5',height: '150px',width: '150px'}, 1000); // 持续时间为1秒
});

4.2 示例

<!DOCTYPE html>
<html>
<head><title>自定义动画示例</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><style>#animateDiv {width: 100px;height: 100px;background-color: lightblue;position: relative;}</style><script>$(document).ready(function(){$("#animateBtn").click(function(){$("#animateDiv").animate({left: '250px',opacity: '0.5',height: '150px',width: '150px'}, 1000);});});</script>
</head>
<body><button id="animateBtn">开始动画</button><div id="animateDiv"></div>
</body>
</html>

5. 元素删除操作

5.1 .remove() 方法

用于移除选定的元素及其子元素。

$("button").click(function(){$("p").remove();
});

5.2 .empty() 方法

用于移除选定元素的子元素,但保留元素本身。

$("button").click(function(){$("div").empty();
});

5.3 示例

<!DOCTYPE html>
<html>
<head><title>元素删除操作示例</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><script>$(document).ready(function(){$("#removeBtn").click(function(){$("#removeParagraph").remove();});$("#emptyBtn").click(function(){$("#emptyDiv").empty();});});</script>
</head>
<body><button id="removeBtn">删除段落</button><p id="removeParagraph">这是一个将被删除的段落。</p><br><button id="emptyBtn">清空 div</button><div id="emptyDiv"><p>这是一个将被清空的 div。</p></div>
</body>
</html>

6. 随机抽奖

6.1 实现思路

  1. 获取所有参与抽奖的元素。
  2. 使用 Math.random() 生成随机数。
  3. 根据随机数选择中奖元素。
  4. 显示中奖结果。

6.2 示例

<!DOCTYPE html>
<html>
<head><title>随机抽奖示例</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><style>.participant {padding: 10px;margin: 5px;background-color: lightgreen;display: inline-block;cursor: pointer;}</style><script>$(document).ready(function(){$("#drawBtn").click(function(){var participants = $(".participant");var total = participants.length;if(total === 0){alert("没有参与者!");return;}var randomIndex = Math.floor(Math.random() * total);var winner = participants.eq(randomIndex);alert("中奖者是:" + winner.text());});});</script>
</head>
<body><h2>参与者列表</h2><div class="participant">参与者1</div><div class="participant">参与者2</div><div class="participant">参与者3</div><div class="participant">参与者4</div><div class="participant">参与者5</div><br><button id="drawBtn">开始抽奖</button>
</body>
</html>

7. 随机选图并放大

7.1 实现思路

  1. 准备一个图片库。
  2. 使用 Math.random() 随机选择一张图片。
  3. 将选中的图片显示在一个模态框中,并放大显示。

7.2 示例

<!DOCTYPE html>
<html>
<head><title>随机选图并放大示例</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><style>.thumbnail {width: 100px;height: 100px;margin: 5px;cursor: pointer;}#modal {display: none;position: fixed;z-index: 1;padding-top: 100px;left: 0;top: 0;width: 100%;height: 100%;overflow: auto;background-color: rgba(0,0,0,0.9);}#modalImage {margin: auto;display: block;max-width: 80%;max-height: 80%;}#closeBtn {position: absolute;top: 50px;right: 35px;color: #fff;font-size: 40px;font-weight: bold;cursor: pointer;}</style><script>$(document).ready(function(){var images = ["https://via.placeholder.com/100?text=Image1","https://via.placeholder.com/100?text=Image2","https://via.placeholder.com/100?text=Image3","https://via.placeholder.com/100?text=Image4","https://via.placeholder.com/100?text=Image5"];$(".thumbnail").click(function(){var index = $(this).index();var selectedImage = images[index];$("#modalImage").attr("src", selectedImage);$("#modal").fadeIn(200);});$("#closeBtn").click(function(){$("#modal").fadeOut(200);});// 点击模态框背景关闭$("#modal").click(function(event){if($(event.target).is("#modal")){$(this).fadeOut(200);}});});</script>
</head>
<body><h2>图片库</h2><img src="https://via.placeholder.com/100?text=Image1" class="thumbnail" alt="Image1"><img src="https://via.placeholder.com/100?text=Image2" class="thumbnail" alt="Image2"><img src="https://via.placeholder.com/100?text=Image3" class="thumbnail" alt="Image3"><img src="https://via.placeholder.com/100?text=Image4" class="thumbnail" alt="Image4"><img src="https://via.placeholder.com/100?text=Image5" class="thumbnail" alt="Image5"><div id="modal"><span id="closeBtn">&times;</span><img id="modalImage" src="" alt="Selected Image"></div>
</body>
</html>

8. 综合案例代码

以下是一个综合应用上述功能的完整示例:

<!DOCTYPE html>
<html>
<head><title>综合应用示例</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><style>.participant {padding: 10px;margin: 5px;background-color: lightgreen;display: inline-block;cursor: pointer;}#modal {display: none;position: fixed;z-index: 1;padding-top: 100px;left: 0;top: 0;width: 100%;height: 100%;overflow: auto;background-color: rgba(0,0,0,0.9);}#modalImage {margin: auto;display: block;max-width: 80%;max-height: 80%;}#closeBtn {position: absolute;top: 50px;right: 35px;color: #fff;font-size: 40px;font-weight: bold;cursor: pointer;}#animateDiv {width: 100px;height: 100px;background-color: lightblue;position: relative;margin: 20px;}</style><script>$(document).ready(function(){// 单击事件显示不同词语$("#showTextBtn").click(function(){var texts = ["你好", "欢迎", "再见", "谢谢", "加油"];var randomIndex = Math.floor(Math.random() * texts.length);$("#displayText").text(texts[randomIndex]);});// 自定义动画$("#animateBtn").click(function(){$("#animateDiv").animate({left: '250px',opacity: '0.5',height: '150px',width: '150px'}, 1000);});// 删除元素操作$("#removeBtn").click(function(){$("#removeParagraph").remove();});// 随机抽奖$("#drawBtn").click(function(){var participants = $(".participant");var total = participants.length;if(total === 0){alert("没有参与者!");return;}var randomIndex = Math.floor(Math.random() * total);var winner = participants.eq(randomIndex);alert("中奖者是:" + winner.text());});// 随机选图并放大var images = ["https://via.placeholder.com/100?text=Image1","https://via.placeholder.com/100?text=Image2","https://via.placeholder.com/100?text=Image3","https://via.placeholder.com/100?text=Image4","https://via.placeholder.com/100?text=Image5"];$(".thumbnail").click(function(){var index = $(this).index();var selectedImage = images[index];$("#modalImage").attr("src", selectedImage);$("#modal").fadeIn(200);});$("#closeBtn").click(function(){$("#modal").fadeOut(200);});// 点击模态框背景关闭$("#modal").click(function(event){if($(event.target).is("#modal")){$(this).fadeOut(200);}});});</script>
</head>
<body><h2>综合应用示例</h2><button id="showTextBtn">显示不同词语</button><p id="displayText">等待显示...</p><button id="animateBtn">开始动画</button><div id="animateDiv"></div><button id="removeBtn">删除段落</button><p id="removeParagraph">这是一个将被删除的段落。</p><h3>参与者列表</h3><div class="participant">参与者1</div><div class="participant">参与者2</div><div class="participant">参与者3</div><div class="participant">参与者4</div><div class="participant">参与者5</div><h3>图片库</h3><img src="https://via.placeholder.com/100?text=Image1" class="thumbnail" alt="Image1"><img src="https://via.placeholder.com/100?text=Image2" class="thumbnail" alt="Image2"><img src="https://via.placeholder.com/100?text=Image3" class="thumbnail" alt="Image3"><img src="https://via.placeholder.com/100?text=Image4" class="thumbnail" alt="Image4"><img src="https://via.placeholder.com/100?text=Image5" class="thumbnail" alt="Image5"><div id="modal"><span id="closeBtn">&times;</span><img id="modalImage" src="" alt="Selected Image"></div>
</body>
</html>

8.1 代码说明

  1. 显示不同词语
    • 点击“显示不同词语”按钮时,从预定义数组中随机选择一条文本显示在段落中。
  2. 自定义动画
    • 点击“开始动画”按钮时,对蓝色方块执行动画,使其向左移动、改变不透明度并增大尺寸。
  3. 删除元素操作
    • 点击“删除段落”按钮时,删除指定的段落元素。
  4. 随机抽奖
    • 点击“参与者”列表中的任意元素时,从参与者中随机选择一个中奖者并弹出提示。
  5. 随机选图并放大
    • 点击任意缩略图时,从预定义数组中随机选择一张图片并显示在模态框中。

8.2 注意事项

  • 跨域问题:使用占位符图片(https://via.placeholder.com/)作为示例图片库。如果使用本地图片路径,请确保路径正确。
  • 模态框背景点击关闭:通过判断点击的目标是否是模态框本身来关闭模态框。
  • 参与者列表:参与者列表中的元素可以通过添加或删除 .participant 类的元素来动态调整。
http://www.dtcms.com/wzjs/391063.html

相关文章:

  • 建设网站工作室的问题疑问百度推广助手app下载
  • 在阿里云做的网站怎么移动青岛seo霸屏
  • 游戏网站banner怎么做百度开店怎么收费
  • 艾乐时代 网站建设自助建站平台源码
  • 网站建设 团队介绍什么叫口碑营销
  • 免费做网站用什么软件如何制作一个自己的网页
  • 云阳网站建设拓客最有效方案
  • 合肥高端网站建设公司哪家好营销渠道有哪几种
  • 真如做网站站点搜索
  • 微博wordpress宁波seo企业推广
  • 百度云怎么做网站空间网站建设是干嘛的
  • 深圳网站建设工作室seo课程培训
  • 中国十大贸易公司排名宁德seo优化
  • 微信小程序网站制作线下引流的八种推广方式
  • 外汇网站怎么做优外汇网站商丘seo优化
  • 自己怎么做网站赚钱seo全称是什么意思
  • 网站开发iso9001香水推广软文
  • 重庆企业网站排名优化方法app香港账号
  • 网站域名能更该吗百度移动端排名
  • 青岛博海建设网站关键词优化案例
  • 政府网站建设和服务网站查询进入
  • 怎么看一个网站是谁做的站长工具pr值查询
  • 东莞建站公司运转全网天下有 名国外域名购买
  • ui设计师能独立做网站吗百度 营销中心
  • 如何创建网站目录百度账号注册入口
  • 女生做网站编辑怎么样病毒营销案例
  • 怎么去投诉做网站的公司产品推广软文
  • 政府机关网站建设的依据网站平台有哪些
  • 东莞常平网站设计seo排名优化软件
  • 人才网站的会计账如何做公司想建个网站怎么弄