1

我已经为输出标签编码,但我无法获得代码的实际输出。

代码如下

<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>
4

1 回答 1

0

你有各种各样的问题。我不认为你想使用oninput, 和 Usingz.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.
});

http://jsfiddle.net/ExplosionPIlls/S5XN6/

于 2013-03-04T03:45:57.220 回答