<html> <head> <script language="javascript"> <!-- function test(){ var x = document.getElementById("txt1"); var y = document.getElementById("output").innerHTML
<html> <head> <script language="javascript"> <!-- function test(){ var x = document.getElementById("txt1"); var y = document.getElementById("output").innerHTML;
<html> <head> <script language="javascript"> <!-- function test(){ var x = document.getElementById("txt1"); var y = document.getElementById("output").innerHTML;
x = Number(x.value); y = Number(y); document.getElementById("output").innerHTML = x + y; } --> </script> </head> <body> <input type="text" id="txt1"> <input type="button" value="押す" onclick="test()"> <div id="output"> 4 </div> </body> </html>
17 :
身内専用テストスレ じゃねーんだよ 他所でやれ
18 :
<html> <head> <script language="javascript"> <!-- function test(){ var x = document.getElementById("txt1"); var y = document.getElementById("txt2"); x = Number(x.value); y = Number(y.value); document.getElementById("output").innerHTML = x + y; } --> </script> </head> <body> <input type="text" id="txt1"> <input type="text" id="txt2"> <input type="button" value="押す" onclick="test()"> <div id="output"> 0 </div> </body> </html>
19 :
<html> <head> <script language="javascript"> var x = 0; var z = 0; <!-- function test(){ var x = document.getElementById("txt1"); var y = document.getElementById("output").innerHTML; var z = document.getElementById("txt2"); x = Number(x.value); y = Number(y); z = Number(z.value); document.getElementById("output").innerHTML = x + y +z; } --> </script> </head> <body> <input type="text" id="txt1"> + <input type="text" id="txt2"> <input type="button" value="=" onclick="test()"> <div id="output"> 0 </div> </body> </html> *グローバル変数を宣言しても、初期の画面に0 0が出ない・・・。
20 :
<html> <head> <script language="javascript"> <!-- var x0 = 0; var z0 = 0; function init(){ document.getElementById("output").innerHTML = x0 + z0; } function test(){ var x = document.getElementById("txt1"); var y = document.getElementById("output").innerHTML; var z = document.getElementById("txt2"); x = Number(x.value); y = Number(y); z = Number(z.value); document.getElementById("output").innerHTML = x + y +z; } --> </script> </head> <body onload="init()"> <input type="text" id="txt1"> + <input type="text" id="txt2"> <input type="button" value="=" onclick="test()"> <div id="output"> </div> </body> </html>