简体   繁体   中英

Simple Calculator in HTML and JavaScript with buttons

I have the following HTML and JavaScript code for a simple calculator.

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 "+">&divide;</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?

I have the following HTML and JavaScript code for a simple calculator.

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 "+">&divide;</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?

I have the following HTML and JavaScript code for a simple calculator.

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 "+">&divide;</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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM