`为什么它在函数之外工作?怎么了?我不明白......尝试添加返回语句 - 仍然没有。 [[]()]()
不起作用:
function changeValue() {
let charge = document.getElementById("myRange").value;
document.getElementById("displayValue").innerHTML = charge;
}
作品:
let charge = document.getElementById("myRange").value;
document.getElementById("displayValue").innerHTML = charge;
我的 HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Battery Emulatior</title>
<link rel="icon" type="image/x-icon" href="favicon.png">
<link rel="stylesheet" href="battery.css">
</head>
<body>
<h1>INTERACTIVE BATTERY EMULATOR</h1>
<p1>Choose the expiration period</p1>
<div class="indicator">
<div class="batteryterminal"></div>
</div>
<div class="slidecontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
</div>
<div id="displayValue"></div>
<script src="battery.js"></script>
</body>
</html>
` 尝试添加返回语句 - 什么都没有
您需要调用该函数才能执行
function changeValue() {
let charge = document.getElementById("myRange").value;
document.getElementById("displayValue").innerHTML = charge;
}
changeValue()