转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/126502059
本文出自【赵彦军的博客】
标签用于定义客户端脚本,比如 JavaScript。
元素既可包含脚本语句,也可以通过 “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>
日志显示:
<!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>