<table class="calc" cellpadding=2>
<td><input type="button" class="calc" id="screen" value="0" ></td>
<td><input type="button" class="calc" id="screen" value="0" ></td>
<tr>
</table>
<table class="calc" cellpadding=2>
<td><button type="button" onclick="pushButton(1)" value="Call2Functions">1</td>
<td><button type="button" onclick="pushButton(2)" value="Call2Functions">2</td>
<td><button type="button" onclick="pushButton(3)" value="Call2Functions">3</td>
<td></td>
</tr>
<div>
<script>
function pushButton(buttonValue) {
if (buttonValue == 'C') {
document.getElementById('screen').value = '0';
}
else {//this is where most changes occured
var x= document.getElementById('screen').value
x =parseInt(x)+ parseInt(buttonValue);
document.getElementById('screen').value=x;
localStorage.setItem('answer', x);
}
}
function calculate(equation) {
var answer = eval(equation);
document.getElementById('screen').value = answer;
}
</script>
你好朋友, 请帮助我..我的问题非常清楚。假设你和朋友一个接一个地点击数字...首先点击数字它应该在第一个按钮本地存储。然后你的朋友点击相同的按钮但现在应该反映在第二个按钮。再次,如果你按下按钮,它应该添加在第一个按钮..所以如何做到这一点,每次我点击我应该存储在本地,所以我不会丢失我的数据
答案 0 :(得分:1)
JavaScript代码是......
function pushButton(buttonValue) {
if (buttonValue == 'C') {
document.getElementById('screen').value = '0';
}
else {//this is where most changes occured
var x= document.getElementById('screen'+buttonValue).value
x =parseInt(x)+ parseInt(buttonValue);
document.getElementById('screen'+buttonValue).value=x;
localStorage.setItem('answer', x);
}
}
function calculate(equation) {
var answer = eval(equation);
document.getElementById('screen'+buttonValue).value = answer;
}
HTML代码就在这里......
<table class="calc" cellpadding=2>
<tr>
<td><input type="button" class="calc" id="screen1" value="0"></td>
<td><input type="button" class="calc" id="screen2" value="0"></td>
<td><input type="button" class="calc" id="screen3" value="0"></td>
</tr>
</table>
<table class="calc" cellpadding=2>
<tr>
<td><button type="button" onclick="pushButton(1)" value="Call2Functions">1</td>
<td><button type="button" onclick="pushButton(2)" value="Call2Functions">2</td>
<td><button type="button" onclick="pushButton(3)" value="Call2Functions">3</td>
</tr>
</table>
对于reff。目的是看my plunker