<body><input type="button" value="1" onclick="one()" id="a1"><input type="button" value="2" onclick="two()" id="a2"><input type="button" value="-" onclick="add()" id="a3" ><input type="button" value="=" onclick="dy()" ><input type="text" value="" id="a4" ></body><script>var a_4 = ""function one(){ var a_1 = document.getElementById("a1").value }function two(){ var a_2 = document.getElementById("a2").value }function add(){ var a_3 = document.getElementById("a3").value }function dy(){ document.getElementById("a4").value = a_4 }</script>
3 回答
已采纳
h5
TA贡献19条经验 获得超9个赞
<body> <input type="button" value="1" onclick="one()" id="a1"> <input type="button" value="2" onclick="two()" id="a2"> <input type="button" value="-" onclick="minus()" id="a3" > <input type="button" value="+" onclick="add()" id="a5" > <input type="button" value="=" onclick="dy()" > <input type="button" value="c" onclick="cl()" > <input type="text" value="" id="a4" > </body> <script> var a_4 = "" function cl(){ a_4="" document.getElementById("a4").value = a_4 } function one(){ a_4 += document.getElementById("a1").value document.getElementById("a4").value = a_4 } function two(){ a_4 += document.getElementById("a2").value document.getElementById("a4").value = a_4 } function minus(){ a_4 += document.getElementById("a3").value document.getElementById("a4").value = a_4 } function add(){ a_4 += document.getElementById("a5").value document.getElementById("a4").value = a_4 } function dy(){ document.getElementById("a4").value = eval(a_4) a_4=document.getElementById("a4").value } </script>
堂堂堂堂糖糖糖童鞋
TA贡献101条经验 获得超58个赞
<script> var a_4 = "" var numbers = [] function one () { var a_1 = document.getElementById("a1").value numbers.push(a_1) } function two() { var a_2 = document.getElementById("a2").value numbers.push(a_2) } function add() { if (!numbers.length) { alert('请先选择一个数字') return } var a_3 = document.getElementById("a3").value numbers.push(a_3) } function dy() { if (numbers.length !== 3) { alert('操作有误') return } if (numbers[1] === '-') { a_4 = numbers[0] * 1 - numbers[2] * 1 } document.getElementById("a4").value = a_4 } </script>
千秋此意
TA贡献158条经验 获得超187个赞
<html> <head> <meta charset="utf-8"> <title>test</title> </head> <body> <input type="button" value="1" onclick="one(this.value)" id="a1" /> <input type="button" value="2" onclick="one(this.value)" id="a2" /> <input type="button" value="-" onclick="calc(this.value)" id="a3" /> <input type="button" value="=" onclick="dy()" /> <input type="button" value="cls" onclick="cls()" /> <input type="text" value="" id="a4" readonly /> </body> <script> var a4 = document.getElementById('a4'); var c = true; a4.value = ''; function one(val) { if (c === false) { cls(); } a4.value += val; } function calc(operator) { if (/\d/.test(a4.value.substr(-1)) && c) { a4.value += operator; } else { alert('请输入正确的表达式!'); } } function dy() { if (!c || !(/^\d+.*\d+$/g.test(a4.value))) return; a4.value += ('=' + new Function('return ' + a4.value)()); c = false; } function cls() { c = true; a4.value = ''; } </script> </html>
添加回答
举报
0/150
提交
取消