javascriptの勉強にと簡易電卓を作りましたが、
こちらでchromeで表示したところ、ボタンを押しても
数字が表示されません。
{などの閉じ忘れなども調べてみましたが、特に不備は見当たりませんでした。
数字が表示されるようにしたいです。
わかる方、よろしくお願いします。
html
1<!DOCtype html> 2<html> 3<head> 4 <meta charset="utf-8"> 5 <title>簡易電卓</title> 6 <script src="main.js"></script> 7 <link rel='stylesheet' href='main.css' type='text/css' /> 8</head> 9<body> 10 11<form name="form" id="calcForm"> 12 <table id="calcTable"> 13 <tr> 14 <td colspan="3"><input type="text" name="text" value="0"></td> 15 <td><input type="button" value="C" onClick="calc('C')"></td> 16 </tr> 17 <tr> 18 <td><input type="button" value="7" onClick="calc('7')"></td> 19 <td><input type="button" value="8" onClick="calc('8')"></td> 20 <td><input type="button" value="9" onClick="calc('9')"></td> 21 <td><input type="button" value="/" onClick="calc('/')"></td> 22 </tr> 23 <tr> 24 <td><input type="button" value="4" onClick="calc('4')"></td> 25 <td><input type="button" value="5" onClick="calc('5')"></td> 26 <td><input type="button" value="6" onClick="calc('6')"></td> 27 <td><input type="button" value="✕" onClick="calc('*')"></td> 28 </tr> 29 <tr> 30 <td><input type="button" value="1" onClick="calc('1')"></td> 31 <td><input type="button" value="2" onClick="calc('2')"></td> 32 <td><input type="button" value="3" onClick="calc('3')"></td> 33 <td><input type="button" value="-" onClick="calc('-')"></td> 34 </tr> 35 <tr> 36 <td><input type="button" value="0" onClick="calc('0')"></td> 37 <td><input type="button" value="." onClick="calc('.')"></td> 38 <td><input type="button" value="+" onClick="calc('+')"></td> 39 <td><input type="button" value="=" onClick="calc('=')"></td> 40 </tr> 41 </table> 42</form> 43 44</body> 45</html>
css
1#calcTable { 2 text-align: center; 3 color:#fff; 4} 5
javascript
1 2function calc(cmd) { 3 if (cmd == "=") { 4 document.form.text.value = eval(document.form.text.value); 5 } 6 else if (cmd == "C") { 7 document.form.text.value = ""; 8 } 9 else { 10 document.form.text.value += cmd; 11 } 12} 13
回答1件
あなたの回答
tips
プレビュー