我已为输出标签编码,但我无法获得代码的实际输出。
代码为
<html>
<head>
</head>
<body>
<script>
function myscript()
{
z.value=parseInt(a.value)+parseInt(b.value);
c.value=parseInt(a.value)-parseInt(b.value);
d.value=parseInt(a.value)*parseInt(b.value);
e.value=parseInt(a.value)/parseInt(b.value);
}
</script>
<form oninput="myScript()">
<input type="range" id="a">
<input type="range" id="b">
<input type="submit"><br/>
Addition<output name="z" for="a b"></output><br/>
Substraction<output name="c" for="a b"></output><br/>
Multiplication<output name="d" for="a b"></output><br/>
Division<output name="e" for="a b"></output>
</form>
</body>
</html>
答案 0 :(得分:0)
你有各种各样的问题。我认为您不想使用oninput
,而使用z.value
等可能无效,但也非常不稳定。尝试类似:
document.querySelector('form').addEventListener('submit', function (e) {
e.preventDefault();
var a = +document.getElementById('a').value,
b = +document.getElementById('b').value;
document.querySelector('[name="z"]').textContent = a + b;
//etc.
});