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

JS Lab

  • 如何用 JavaScript 在浏览器中弹窗
  • 如何在 JavaScript 中制作鼠标滑过按钮改变背景颜色
  • 如何在 JS 中点击按钮使数字增加
  • 如何在 JS 中循环打印多少次
HTML
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>JS Lab</title><link rel="stylesheet" href="css/style.css">
</head>
<body><button class="btn" onclick="alertBtn()">Alert Button</button><hr><button class="btn" id="hoverButton">Hover Button</button><hr><button class="btn" id="increaseButton">Incrementing Button</button><span id="number" class="even">0</span><hr><p class="p-loop">For Loops: Print "Hello!" 10 times</p><div id="container"></div>
</body>
<script async src="js/lab.js"></script>
</html>
CSS
body{font-family:Arial; font-size:16px;}
hr{border:1px dashed #ddd;}
.btn{padding:8px 20px; margin: 5px 0;border-radius: 100px;border:1px solid #aaa;}
.btn:hover{background:#fff;}
#hoverButton{background:green; color:#fff; border:0;}
#number{font-size: 20px; margin-left:15px;}
.p-loop{font-weight: bold;}
.odd {color: blue;}
.even {color: red;}
JavaScript
// Alert 
function alertBtn() {alert("Hello world!");
}// Hover Button
let hoverButton = document.getElementById('hoverButton');
hoverButton.onmouseover = function() {this.style.backgroundColor = 'orange'; 
};
hoverButton.onmouseout = function() {this.style.backgroundColor = ''; 
};// Incrementing Button
document.getElementById('increaseButton').addEventListener('click', function() {let numberElement = document.getElementById('number');let currentNumber = parseInt(numberElement.textContent, 10);currentNumber += 1; let newClass = currentNumber % 2 === 0 ? 'even' : 'odd';numberElement.textContent = currentNumber;numberElement.className = newClass;
});// For Loops
for (let i = 0; i < 10; i = i + 1) {document.getElementById('container').append('Hello! ');
}// Change Font Color
function changeFontColor() {let changeButton = document.getElementById("pColor"); let color = changeButton.style.color;if (color == "red") { changeButton.style.color = 'blue';} else {changeButton.style.color = 'red';}
}
http://www.lryc.cn/news/356204.html

相关文章:

  • Vue:快速上手
  • HTML并集,交集,子代,后代选择器
  • 关于pdfbox读取pdf
  • 汽车电子零部件(14):TMS热管理系统
  • 代码模板,Cookie和Session
  • Nginx配置及优化
  • HashMap在Go与Java的底层实现与区别
  • 搜维尔科技:使用Haption Virtuose 6D 力反馈通过机器人和虚拟现实完成远程操作项目
  • 【Python】WHEELTEC GPS G60主代码读取传感器数据代码(Windows系统)
  • 【Vue】Vue2与Vue3的区别
  • 马斯克的 xAI 帝国!60亿融资背后的超级布局?
  • 互联网医院开发:引领智慧医疗新时代
  • 民国漫画杂志《时代漫画》第18期.PDF
  • java.lang.NumberFormatException: For input string:
  • 从零开始搭建Springboot项目脚手架4:保存操作日志
  • 持续总结中!2024年面试必问 20 道 Rocket MQ面试题(一)
  • 生成式AI的GPU网络技术架构
  • 旅游卡在哪里拿货?千益畅行旅游卡源头
  • 代码随想录算法训练营第四十一天| 509. 斐波那契数 、70. 爬楼梯 、746. 使用最小花费爬楼梯
  • Ribbon负载均衡(自己总结的)
  • Leetcode 力扣92. 反转链表 II (抖音号:708231408)
  • OSI七层模型和TCP/IP四层模型的区别
  • 在虚拟机上安装MySQL和Hive
  • Vue 2 和 Vue 3 中同步和异步
  • ssm150旅游网站的设计与实现+jsp
  • 【加密与解密(第四版)】第十四章笔记
  • 鸿蒙系统和安卓系统通过termux搭建Linux系统—Centos
  • 数据结构的希尔排序(c语言版)
  • 使用Node.js搭建服务器
  • 网络编程——多进程的服务器