Advertisement
giangnhauqe

bai 1 lad 9

Oct 27th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.22 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. </head>
  7.  
  8. <body>
  9. <table border="1">
  10.     <tr>
  11.         <td>
  12.             A
  13.         </td>
  14.         <td colspan="4">
  15.         <input type="text" id="a" pattern="[0-9]+" required="required" />
  16.         </td>
  17.     </tr>
  18.     <tr>
  19.         <td>
  20.             B
  21.         </td>
  22.         <td colspan="4">
  23.         <input type="text" id="b" pattern="[0-9]+" required="required" />
  24.         </td>
  25.     </tr>
  26.     <tr>
  27.         <td>
  28.             Phép Tính
  29.         </td>
  30.         <td>
  31.        
  32.         +<input type="radio" name="pt" id="cong"  required="required" value="+" />
  33.         </td>
  34.         <td>
  35.        
  36.         -<input type="radio" name="pt" id="tru"  required="required" value="-" />
  37.         </td>
  38.         <td>
  39.        
  40.         *<input type="radio" name="pt" id="nhan"  required="required" value="*" />
  41.         </td>
  42.         <td>
  43.        
  44.         /<input type="radio" name="pt" id="chia"  required="required" value="/" />
  45.         </td>
  46.     </tr>
  47.     <tr>
  48.         <td>
  49.         Kết quả
  50.         </td>
  51.         <td colspan="4">
  52.             <textarea id="kq" disabled="disabled" > </textarea>
  53.         </td>
  54.     </tr>
  55.     <tr>
  56.         <td>
  57.         </td>
  58.         <td colspan="4">
  59.             <input type="button" value="caculate" onclick="tinh()" />
  60.         </td>
  61.     </tr>
  62. </table>
  63. <script>
  64.     function kt()
  65.     {
  66.        
  67.         //x=parseInt(a.value);
  68.         //y=parseInt(b.value);
  69.         if(isNaN(a.value)||isNaN(b.value))
  70.             return (0);
  71.         else
  72.             return (1);
  73.     }
  74.     function tinh()
  75.     {
  76.         if(kt()==0) alert(" A hoac B không phải là số ");
  77.         else
  78.         {
  79.             if(cong.checked==true)
  80.             {
  81.                 kq.value=parseInt(a.value)+eval(b.value);
  82.             }
  83.             else
  84.             {
  85.                 if(tru.checked==true)
  86.                 kq.value=parseInt(a.value)-eval(b.value);
  87.                     else
  88.                     {
  89.                         if(chia.checked==true)
  90.                         kq.value=parseInt(a.value)/eval(b.value);
  91.                         else
  92.                         {
  93.                             if(nhan.checked==true)
  94.                             kq.value=parseInt(a.value)*eval(b.value);
  95.                         }
  96.                     }
  97.             }
  98.         }
  99.     }
  100.    
  101.    
  102. </script>
  103. </body>
  104. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement