A calculator I wrote a long time ago was written when Baidu knew how to answer a question,
By accident, I felt a little interesting and sent it out.
Html code
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> calculator </title>
<Style type = "text/css">
Input {
Width: 50px;
Margin: 5px
}
</Style>
<Script type = "text/javascript" defer = "defer">
Function add (s ){
Var t = document. getElementById ("text ");
Switch (s ){
Case '+ ':
Case '-':
Case '*':
Case '/':
If (t. value = ''){
T. value = '0' + '\ n' + s;
} Else {
T. value + = '\ n' + s;
}
Break;
Case '= ':
T. value = eval (t. value. replace (/<[^>] *> | \ n/igm ,''))
Break;
Case 'C ':
T. value = '0 ';
Break;
Case 'ce ':
Tt. value = t. value. substr (0, t. value. length-1)
Break;
Default:
If (t. value = '0 '){
T. value = s;
} Else {
If (t. value. substr (t. value. length-1, 1). match (/[\ + \-\ * \/] $/igm )){
T. value + = '\ n' + s;
} Else {
T. value + = ''+ s;
}
}
}
}
</Script>
</Head>
<Body>
<Div>
<Textarea id = "text" style = "width: 200px; height: 100px"> 0 </textarea>
<Input type = "button" value = "1" onclick = "add (1)"/>
<Input type = "button" value = "2" onclick = "add (2)"/>
<Input type = "button" value = "3" onclick = "add (3)"/>
<Input type = "button" value = "4" onclick = "add (4)"/>
<Input type = "button" value = "5" onclick = "add (5)"/>
<Input type = "button" value = "6" onclick = "add (6)"/>
<Input type = "button" value = "7" onclick = "add (7)"/>
<Input type = "button" value = "8" onclick = "add (8)"/>
<Input type = "button" value = "9" onclick = "add (9)"/>
<Input type = "button" value = "0" onclick = "add (0)"/>
<Input type = "button" value = "." onclick = "add ('.')"/>
<Input type = "button" value = "+" onclick = "add ('+')"/>
<Input type = "button" value = "-" onclick = "add ('-')"/>
<Input type = "button" value = "*" onclick = "add ('*')"/>
<Input type = "button" value = "/" onclick = "add ('/')"/>
<Input type = "button" value = "=" onclick = "add ('=')"/>
<Input type = "button" value = "c" onclick = "add ('C')"/>
<Input type = "button" value = "ce" onclick = "add ('ce ')"/>
</Div>
</Body>
</Html>
Author: "linfeng xiaozhu"