js if 判斷的使用

!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>同志交友</title>
<style>
input {
width: 300px;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
}
button {
padding: 10px 20px;
border: 1px solid #ccc;
background: #f5f5f5;
}
#res {
margin-top:20px;
width: 300px;
min-height: 100px;
padding: 10px;
border:1px solid #ccc;
}html

</style>
</head>
<body>
<h1>同志交友</h1>
<hr>
<h3>請輸入您的成績:</h3>
<input type="number" id="score">
<button onclick="makeScore()">提交</button>函數


<div id="res"></div>htm


<script>
//聲明函數
function makeScore() {
//獲取用戶輸入的成績
var score = Number(document.getElementById('score').value);ip

//對成績進行判斷
var resContent = ''; //空字符串 聲明定義 變量
if (score >= 90) {
resContent = '不錯哦,小同志,很優秀'; //修改變量的值
} else if (score >= 80) {
resContent = '小同志,還行';
} else if (score >= 60) {
resContent = '小同志,及格了';
} else {
resContent = '你不是個人同志';
}字符串


//把結果寫入到div中 id=res
document.getElementById('res').innerHTML = resContent;get

}input

</script>
</body>
</html>it

相關文章
相關標籤/搜索