[英]Simple Calculator in HTML and JavaScript with buttons
I have the following HTML and JavaScript code for a simple calculator.我有以下 HTML 和 JavaScript 代码用于一个简单的计算器。
HTML: HTML:
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
<script src="calculator.js" defer></script>
</head>
<body>
<h1>Calculator</h1>
First value: <input name="number1" type="text" size=10 id='num1'/>
<fieldset>
<label for "+">+</label>
<input type="radio" id="+" value ="+" name=calculation/>
<br>
<label for "+">-</label>
<input type="radio" id="-" value ="-" name=calculation/>
<br>
<label for "+">x</label>
<input type="radio" id="x" value ="x" name=calculation/>
<br>
<label for "+">÷</label>
<input type="radio" id="div" value ="div" name=calculation/>
</fieldset>
Second value: <input name="number2" type="text" size=10 id='num2'/> <input type="submit" value="compute" onclick=""/>
<br>
Result: <input id='result' readonly ></td>
</body>
</html>
And the result looks like this:结果如下所示:
However, I want to create something like this:但是,我想创建这样的东西:
Then it looks like I have to change the width for the radio buttons and change the color for the buttons.然后看起来我必须更改单选按钮的宽度并更改按钮的颜色。 And, how do I come up with the correct JavaScript code?而且,我如何想出正确的 JavaScript 代码?
I have the following HTML and JavaScript code for a simple calculator.我有以下 HTML 和 JavaScript 代码用于一个简单的计算器。
HTML: HTML:
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
<script src="calculator.js" defer></script>
</head>
<body>
<h1>Calculator</h1>
First value: <input name="number1" type="text" size=10 id='num1'/>
<fieldset>
<label for "+">+</label>
<input type="radio" id="+" value ="+" name=calculation/>
<br>
<label for "+">-</label>
<input type="radio" id="-" value ="-" name=calculation/>
<br>
<label for "+">x</label>
<input type="radio" id="x" value ="x" name=calculation/>
<br>
<label for "+">÷</label>
<input type="radio" id="div" value ="div" name=calculation/>
</fieldset>
Second value: <input name="number2" type="text" size=10 id='num2'/> <input type="submit" value="compute" onclick=""/>
<br>
Result: <input id='result' readonly ></td>
</body>
</html>
And the result looks like this:结果如下所示:
However, I want to create something like this:但是,我想创建这样的东西:
Then it looks like I have to change the width for the radio buttons and change the color for the buttons.然后看起来我必须更改单选按钮的宽度并更改按钮的颜色。 And, how do I come up with the correct JavaScript code?而且,我如何想出正确的 JavaScript 代码?
I have the following HTML and JavaScript code for a simple calculator.我有以下 HTML 和 JavaScript 代码用于一个简单的计算器。
HTML: HTML:
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
<script src="calculator.js" defer></script>
</head>
<body>
<h1>Calculator</h1>
First value: <input name="number1" type="text" size=10 id='num1'/>
<fieldset>
<label for "+">+</label>
<input type="radio" id="+" value ="+" name=calculation/>
<br>
<label for "+">-</label>
<input type="radio" id="-" value ="-" name=calculation/>
<br>
<label for "+">x</label>
<input type="radio" id="x" value ="x" name=calculation/>
<br>
<label for "+">÷</label>
<input type="radio" id="div" value ="div" name=calculation/>
</fieldset>
Second value: <input name="number2" type="text" size=10 id='num2'/> <input type="submit" value="compute" onclick=""/>
<br>
Result: <input id='result' readonly ></td>
</body>
</html>
And the result looks like this:结果如下所示:
However, I want to create something like this:但是,我想创建这样的东西:
Then it looks like I have to change the width for the radio buttons and change the color for the buttons.然后看起来我必须更改单选按钮的宽度并更改按钮的颜色。 And, how do I come up with the correct JavaScript code?而且,我如何想出正确的 JavaScript 代码?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.