用HTML写一个输出课程成绩——变量声明和变量赋值的代码
时间: 2024-01-16 15:40:26 浏览: 99
编一个程序,定义结构类型(有学号、姓名、性别和程序设计成绩四个字段),声明该结构类型变量,用赋值语句对该变量赋值以后再输出。
<!DOCTYPE html>
<html>
<head>
<title>课程成绩</title>
</head>
<body>
<h1>课程成绩</h1>
<p>以下是我的课程成绩:</p>
<!-- 变量声明 -->
<script>
var mathScore;
var englishScore;
var scienceScore;
</script>
<!-- 变量赋值 -->
<script>
mathScore = 90;
englishScore = 85;
scienceScore = 95;
</script>
<ul>
<li>数学成绩: <span id="mathScore"></span></li>
<li>英语成绩: <span id="englishScore"></span></li>
<li>科学成绩: <span id="scienceScore"></span></li>
</ul>
<!-- 输出变量 -->
<script>
document.getElementById("mathScore").innerText = mathScore;
document.getElementById("englishScore").innerText = englishScore;
document.getElementById("scienceScore").innerText = scienceScore;
</script>
</body>
</html>
阅读全文