如何在<output>标签中进行更多操作?</output>

时间:2013-03-04 03:40:27

标签: javascript html html5 output

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

代码为

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

1 个答案:

答案 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.
});

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