登录  | 立即注册

游客您好!登录后享受更多精彩

查看: 920|回复: 0

[js,sql,html教程] 【HTML】简易计算器源码

[复制链接]

444

主题

509

帖子

2051

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2051

荣誉管理论坛元老

发表于 2021-6-30 23:33:52 来自手机 | 显示全部楼层 |阅读模式 来自:
  1. <!doctype html>$ Y' h3 j1 j. g5 x8 L
  2. <html>
    * q& d- ~) p7 G2 U" C4 D
  3.     <head>
    4 L% H! b4 p- N! d* v9 G9 H3 q
  4.         <script>
    & C6 [6 h; s% i, Y8 |8 F
  5.             function insert(num){( [3 Y$ D  A2 D
  6.                 document.form.textview.value = document.form.textview.value+num
    ( y& V. [# y% ]6 m( Q
  7.             }& A- _. G4 m  h& n5 ^# a. A
  8.             function equal(){  R/ k' S5 `+ D. W- ?5 I) j
  9.             
    $ ?' c2 F0 z/ J6 l$ F0 M
  10.                 var exp = document.form.textview.value( p5 j, T: k* q
  11.                 insert("=")
    9 R; T; I2 e% \1 n7 L
  12.                 if(exp){0 O. P/ v* V0 @( F$ C
  13.                     document.form.textview.value =document.form.textview.value + eval(exp)! Y  a; q& z& h0 T4 @* p* n
  14.                 }
    $ }" ~- O+ x. i# M+ ]
  15.             }1 q% d# s, ~2 w' X1 ]- e
  16.             function clean(){
    * B$ D$ h! W; N0 d8 J2 k" j; ~$ m) [
  17.                 document.form.textview.value = ""% T9 e) a- R' G: H) v! r

  18. 3 s, ?+ l  S0 V- o8 S2 Y
  19.             }% `6 Q; q( B& m+ u+ E6 t
  20.             function back(){
    + j0 s) K7 |" ~; w  W6 P$ W! U
  21.                 var exp = document.form.textview.value
    1 O7 P. T( `, G& z
  22.                 document.form.textview.value = exp.substring(0,exp.length-1)
    0 h3 E/ g, V1 ?, W' y
  23.             }  u& S: s3 ]1 [; D+ E
  24.         </script>
    7 z1 o: w2 u$ Y) _: L
  25.         <style>
    9 x+ u8 ~0 P, O- H: F) x
  26.             *{3 U) U( |- J( W, T4 j" {8 A
  27.                 margin: 0;
    ! W6 [* p7 Z* x# ?7 R! _1 }& Q
  28.                 padding: 0;% k- V5 B; m3 R% V& J, f
  29.             }  r3 o. ~1 N1 Q- T6 v
  30.             td{
    $ g( O* B6 L! X, k
  31.                 width: 100px;5 f& Y" w3 B( G4 c5 e, M
  32.                 height: 100px;
    3 B9 f; S2 H( Q! _* t- A  V
  33.             }) `' l  N, o( j
  34.             .button{
    " R. l, y. q7 a8 A) o  {1 p% ?
  35.                 height:100%;- ]  L$ |* v3 f3 }
  36.                 width:100%;% d" z* h: ]: K- Q2 L1 B
  37.                 font-size: 25px;
    3 G  F& b6 o( w6 {
  38.                 margin: 10px;
    # I, I5 \) @4 n: V# j/ N4 [
  39.                 cursor: pointer;
    ; w/ j( A0 X" D5 W* c
  40.                 background: #607d8b;" @2 r; \" l; v+ c- F  k! u
  41.                 border: none;) z, v0 l! M6 K. R2 M4 |! w
  42.             }8 P  P5 e. b6 V% M
  43.             .textview{1 y' Z0 P, j5 W1 n8 v9 _5 X
  44.                 width: 400px;$ I* \7 j$ @% B; e9 L5 y
  45.                 margin: 10px;
    4 e9 \2 Q+ n8 O& E
  46.                 font-size: 50px;
    " Y; A: J. J0 a8 H# _8 @% x+ a8 d
  47.                 padding: 5px;3 ~, h* K& D/ h" I# o
  48.                 border: none;, v$ ?6 j! m3 Y' ^+ k2 m
  49.                 color: #607d8b;
    ' h- ]8 R5 d) S
  50.             }) t- v7 O. B5 p2 c+ K9 S) g
  51.             .main{3 m1 v+ H9 Y1 |' G1 l
  52.                 position: absolute;
    1 B  o4 y. \. y4 R5 ~
  53.                 top: 50%;3 T, f5 w; c' B/ p1 ?, g" F- [
  54.                 left: 50%;
    " b/ r  i7 ^. z4 I/ q
  55.                 transform: translateX(-50%) translateY(-50%);8 C. r( C! {+ c; s+ q2 v. _
  56.             }8 G6 j( J" ^/ [9 }
  57.             .bg{- _+ I  R9 m" n2 I1 b; x7 I
  58.                 width:100%;0 {& D: x- W; [  ~; a
  59.                 height:100vh;1 h& I  s) K4 I6 X: E8 m
  60.                 background: linear-gradient(to right, #e91e63, #3f51b5)
    6 \2 _) u' J2 f# N
  61.             }
    7 H& D- k- F( p, A. }
  62.         </style>
    2 }" s. _3 M: E: v& J! J
  63.     </head>% ]& [  T4 y: O" ]* h2 {
  64.     <body>' I" O  l; e0 U
  65.         <div class="bg">
    % F# G3 W; K8 N$ O
  66.         <div class="main">
    ' [! o& Y/ W6 e# w
  67.             <form name="form">
    4 }! V* a5 t2 e& I9 `
  68.                 <input class="textview" name="textview">
    7 D) _' E" T, @, U3 L5 Z5 g* n, ?
  69.             </form>
    % b, x& u2 @( ~8 D
  70.             <table>, |2 u* n# x' z# Y1 d+ ?
  71.                 <tr>
    * t; f4 w1 C, @" a% O
  72.                     <td><input class ="button" type="button" value="C" onclick="clean()"></td>* ?" h1 O/ t* q. j$ Q+ I
  73.                     <td><input class ="button" type="button" value="<" onclick="back()"></td>
    # U6 {/ Q; ~4 Y4 O! S
  74.                     <td><input class ="button" type="button" value="/" onclick="insert('/')"></td>
      h! ^' {5 ^) N* H& W
  75.                     <td><input class ="button" type="button" value="X" onclick="insert('*')"></td>% k% f% ?$ T7 O; m" E
  76.                 </tr>
    * {. k# P( ]. i- S6 g# E  p2 \+ B# k9 h
  77.                 <tr>
    5 `3 q. n& q% `/ V  c' V' M. @' u
  78.                     <td><input class ="button" type="button" value="7" onclick="insert(7)"></td>
    - K' p# g" a$ j  @$ P
  79.                     <td><input class ="button" type="button" value="8" onclick="insert(8)"></td>
    8 n, ~7 A  I+ B: e5 l9 p
  80.                     <td><input class ="button" type="button" value="9" onclick="insert(9)"></td>
    * _, c6 }% ?9 ^% c" V- q
  81.                     <td><input class ="button" type="button" value="-" onclick="insert('-')"></td>- {. @5 \( U( O
  82.                 </tr>5 I) N5 {  Z* F6 e! L* z
  83.                 <tr>$ g& I- Z! v% W! ~' A
  84.                     <td><input class ="button" type="button" value="4" onclick="insert(4)"></td>' f$ \' v/ g" e, p2 f: C0 h
  85.                     <td><input class ="button" type="button" value="5" onclick="insert(5)"></td>
    9 Q4 }# D- R( [3 V9 R: y1 Z8 H1 E
  86.                     <td><input class ="button" type="button" value="6" onclick="insert(6)"></td>
    8 S+ V" _$ C$ ]: Q0 f2 C- ^
  87.                     <td><input class ="button" type="button" value="+" onclick="insert('+')"></td>
    7 s; d. O( T, D: Z# W! r; i# r
  88.                 </tr>8 D2 r0 _+ A$ u& z
  89.                 <tr>7 c" \  w: r, h$ b; _5 C6 N" p5 @2 x
  90.                     <td><input class ="button" type="button" value="1" onclick="insert(1)"></td>' Y- g8 F& o( ?3 y! }! t8 P: X
  91.                     <td><input class ="button" type="button" value="2" onclick="insert(2)"></td>
    0 B' I  q9 l+ _- S9 r7 y: b
  92.                     <td><input class ="button" type="button" value="3" onclick="insert(3)"></td>( ], U$ [8 j+ P
  93.                     <td rowspan=5><input class ="button" style="height:106" type="button" value="=" onclick="equal()"></td>
    : @$ i& x* M5 ?6 |' \
  94.                 </tr>  \" I( k, ^( T" w( E. F- T$ M
  95.                 <tr>
    5 ^3 h- K. |' e
  96.                     <td colspan=2><input class ="button" style="width:106" type="button" value="0" onclick="insert(0)"></td>* {0 L; N& Z/ n  [: p7 i
  97.                     <td><input class ="button" type="button" value="." onclick="insert('.')"></td>6 T* ]2 I+ m- Y) _1 l
  98.                 </tr>: ?' ~/ ^: f' f0 N  t0 D' a
  99.             </table>+ Q. S* d% d1 K( H* S; x
  100.         </div>; i/ }3 Y, W/ Q2 C, M
  101.         </div>
    0 l* W3 y& s( Q: `
  102.     </body>
    ' j* ?; }$ Q, P# D, B- s$ D7 m
  103. </html>) q) J* a' }" L1 y1 d2 E
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|星空社区 |网站地图

GMT+8, 2024-4-29 12:14 , Processed in 0.054483 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表