JSFiddle - React, Tailwind, and code Playground
HTML
simple counter:
<button id="minus_btn" onclick="minus_btn()">-</button>
<span id="rz">0</span>
<button id="plus_btn" onclick="plus_btn()">+</button>
<hr>
simple calculator:
<input type="text" id="x_in"/>
(+ / − / × / ÷)
<input type="text" id="y_in" />
<button id="operation_btn" onclick="operation()">加/減/乘/除</button>
JavaScript
var rz = 0;
const minus_btn = () => {
rz = rz - 1;
alert(rz);
document.querySelector('#rz').textContent = rz;
}
const plus_btn = () => {
rz = rz + 1;
alert(rz);
document.querySelector('#rz').textContent = rz;
}
const operation = () => {
const x_in = parseInt(document.querySelector('#x_in').value);
const y_in = parseInt(document.querySelector('#y_in').value);
alert("x_in + y_in = " + (x_in + y_in));
alert("x_in - y_in = " + (x_in - y_in));
alert("x_in × y_in = " + (x_in * y_in));
alert("x_in ÷ y_in = " + (x_in / y_in));
}