Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!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=utf-8" />
- <title>Untitled Document</title>
- </head>
- <body>
- <table border="1">
- <tr>
- <td>
- A
- </td>
- <td colspan="4">
- <input type="text" id="a" pattern="[0-9]+" required="required" />
- </td>
- </tr>
- <tr>
- <td>
- B
- </td>
- <td colspan="4">
- <input type="text" id="b" pattern="[0-9]+" required="required" />
- </td>
- </tr>
- <tr>
- <td>
- Phép Tính
- </td>
- <td>
- +<input type="radio" name="pt" id="cong" required="required" value="+" />
- </td>
- <td>
- -<input type="radio" name="pt" id="tru" required="required" value="-" />
- </td>
- <td>
- *<input type="radio" name="pt" id="nhan" required="required" value="*" />
- </td>
- <td>
- /<input type="radio" name="pt" id="chia" required="required" value="/" />
- </td>
- </tr>
- <tr>
- <td>
- Kết quả
- </td>
- <td colspan="4">
- <textarea id="kq" disabled="disabled" > </textarea>
- </td>
- </tr>
- <tr>
- <td>
- </td>
- <td colspan="4">
- <input type="button" value="caculate" onclick="tinh()" />
- </td>
- </tr>
- </table>
- <script>
- function kt()
- {
- //x=parseInt(a.value);
- //y=parseInt(b.value);
- if(isNaN(a.value)||isNaN(b.value))
- return (0);
- else
- return (1);
- }
- function tinh()
- {
- if(kt()==0) alert(" A hoac B không phải là số ");
- else
- {
- if(cong.checked==true)
- {
- kq.value=parseInt(a.value)+eval(b.value);
- }
- else
- {
- if(tru.checked==true)
- kq.value=parseInt(a.value)-eval(b.value);
- else
- {
- if(chia.checked==true)
- kq.value=parseInt(a.value)/eval(b.value);
- else
- {
- if(nhan.checked==true)
- kq.value=parseInt(a.value)*eval(b.value);
- }
- }
- }
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement