JacaScript大小写字母敏感。
JavaScript输出 document.write("输出测试格式");console.log("输出测试调试")
alert("弹窗");
每句以;隔开。
内联样式:<script type="text/javascript">
document.write("输出测试格式");
</script>
外联样式:<script type="text/javascript" src="样式地址"></script>
变量首字母不允许为数字,应用字母或_或$,用英文来命名。
不允许用以下关键字命名
break var new case finally return else catch for switch while continue function delete in try with if default do
void this typeof throw
实例
<!DOCTYPE html>
<html>
<head>
<title>JavaScript学习</title>
<link rel="icon" type="images/x-icon" href="static/images/favicon.ico">
<script type="text/javascript">
document.write("输出测试格式");
</script>
</head>
<body>
</body>
</html>点击 "运行实例" 按钮查看在线实例
变量声明,一条语句可以声明多个变量。
var 声明 变量
新的声明方式:let声明变量/const声明常量
=号为赋值,==号为等于,===全等于。
[]声明为数组。
对象object,用{}来写。var a={name:"灭绝",age:"18"};
&& 所有值为真即为真true
|| 任何一边为真即为真,双边都为假为假falsc
!取反,值为真时取反truc
<!DOCTYPE html>
<html>
<head>
<title>JavaScript学习判断是否为闰年</title>
<link rel="icon" type="images/x-icon" href="static/images/favicon.ico">
<script type="text/javascript">
var year=[2000];
document.write(year);
if (year%4 !=0) {
document.write("不是闰年");
}else{
document.write("是闰年");
}
</script>
</head>
<body>
</body>
</html>点击 "运行实例" 按钮查看在线实例
<!DOCTYPE html>
<html>
<head>
<title>JavaScript学习判断成绩优秀</title>
<link rel="icon" type="images/x-icon" href="static/images/favicon.ico">
<script type="text/javascript">
// document.write("输出测试格式")
var a=87;
if (a>=101) {
document.write("分数是不是超出范围了");
}else if(a>=90) {
document.write("优秀");
}else if(a>=80 ){
document.write("良好");
}else if(a>=70){
document.write("良");
}else if(a>=60){
document.write("及格");
}else if(a>=0){
document.write("不及格");
}else{
document.write("没有此类分数");
}
</script>
</head>
<body>
</body>
</html>
<!-- 给学生的具体成绩划分等级,优秀(90-100)、良好(80-89)、良(70-79)、及格(60-69)、不及格(0-59),输出该学生的成绩是哪个阶段 -->点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号