0
点赞
收藏
分享

微信扫一扫

Html第3集:script、for循环、while、switch


文章目录

  • ​​script​​
  • ​​for循环、while、switch​​
  • ​​进制转换​​
  • ​​比较大小​​

script

  • ​<script>​​ 标签用于定义客户端脚本,比如 JavaScript。
  • ​<script>​​ 元素既可包含脚本语句,也可以通过 “src” 属性指向外部脚本文件。
  • ​JavaScript​​ 通常用于图像操作、表单验证以及动态内容更改。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试</title>

<script>

console.log("这是我的第一行js代码");
a = 1
b = 20
c = a + b
console.log("相加 " + c)

</script>

</head>
<body>

</body>
</html>

日志显示:

Html第3集:script、for循环、while、switch_css

for循环、while、switch

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试</title>

<script>

//for
for (let i = 0; i < 5; i++) {
console.log("for " + i)
}

//while
tag = 5
while (tag) {
tag--
console.log("while " + tag)
}

//switch
num = 10
switch (num){
case 10:
console.log("switch 10")
break
case 1:
console.log("switch 1")
break

}

</script>


</head>
<body>

</body>
</html>

进制转换

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试</title>

<script>

price = 2.0
//将price 二进制转换
price2 = price.toString(2)
//将price 十六制转换
price3 = price.toString(16)

</script>


</head>
<body>

</body>
</html>

比较大小

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试</title>

<script>

a = 1
b = "abc"
c = false
console.log("比较 " + (a === 1))
console.log("比较 " + (b === "abc"))
console.log("比较 " + (b === "bc"))
console.log("比较 " + (c === true))

</script>

</head>
<body>

</body>
</html>

Html第3集:script、for循环、while、switch_css_02


举报

相关推荐

0 条评论