2013-03-04 16 views
1

我已經編碼爲輸出標籤,但我無法獲得代碼的實際輸出。如何在<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> 
+0

歡迎堆棧溢出!你的問題是什麼?你有什麼嘗試? – 2013-03-04 03:42:12

+1

以使用腳本獲取輸出標籤。我會返回a和b變量的值作爲對它們的操作 – 2013-03-04 03:44:26

+0

呵呵。我不知道''和'ininput' [實際存在](http://html5doctor.com/the-output-element/)。 – josh3736 2013-03-04 03:51:07

回答

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/

相關問題