-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
118 lines (98 loc) · 2.7 KB
/
app.js
File metadata and controls
118 lines (98 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
$(function () { //$延緩執行
var currentText = '';
var number = '';
//var newNumber = '';
var operator = '';
$('#add').on('click',function() { //when click 執行function()
operator = '+';
number = currentText;
currentText = '';
render();
})
$('#minus').on('click',function() { //when click 執行function()
operator = '-';
number = currentText;
currentText = '';
render();
})
$('#cross').on('click',function() { //when click 執行function()
operator = '*';
number = currentText;
currentText = '';
render();
})
$('#divide').on('click',function() { //when click 執行function()
operator = '/';
number = currentText;
currentText = '';
render();
})
$('#equal').on('click',function() { //when click 執行function()
if(operator === '+'){
currentText = parseInt((parseInt(number, 10) + parseInt(currentText,10)).toString(10));
render();
}
else if(operator === '-'){
currentText = parseInt((parseInt(number, 10) - parseInt(currentText,10)).toString(10));
render();
}
else if(operator === '*'){
currentText = parseInt((parseInt(number, 10) * parseInt(currentText,10)).toString(10));
render();
}
else if(operator === '/'){
currentText = parseInt((parseInt(number, 10) / parseInt(currentText,10)).toString(10));
render();
}
})
$('#btn1').on('click',function() { //when click 執行function()
//alert('hello jquery');
//$('#message').text('吃午餐');
//$('#message').addClass('green');
currentText = currentText + '1';
render();
})
$('#btn2').on('click',function() { //when click 執行function()
currentText = currentText + '2';
render();
})
$('#btn3').on('click',function() { //when click 執行function()
currentText = currentText + '3';
render();
})
$('#btn4').on('click',function() { //when click 執行function()
currentText = currentText + '4';
render();
})
$('#btn5').on('click',function() { //when click 執行function()
currentText = currentText + '5';
render();
})
$('#btn6').on('click',function() { //when click 執行function()
currentText = currentText + '6';
render();
})
$('#btn7').on('click',function() { //when click 執行function()
currentText = currentText + '7';
render();
})
$('#btn8').on('click',function() { //when click 執行function()
currentText = currentText + '8';
render();
})
$('#btn9').on('click',function() { //when click 執行function()
currentText = currentText + '9';
render();
})
$('#btn0').on('click',function() { //when click 執行function()
currentText = currentText + '0';
render();
})
$('#btnclear').on('click',function() { //when click 執行function()
currentText = '';
render();
})
function render(){
$('#message').text(currentText);
}
});