Advertisement
Guest User

bai tap

a guest
Oct 24th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.47 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.  <h1 align="center" id="1"> Nhập và sắp xếp mảng </h1>
  10.  Nhập phần tử thứ<input id="thu" name="pt" value="1" disabled="disabled" pattern="[0-9]*" type="text" /><p/>
  11.  Giá trị  <input id="gt" name="gt" pattern="[0-9]*" type="text" /><p/>
  12.  <input type="button" name="them" value="thêm vào mảng" onclick="themvao()" />
  13.  <input type="button" name="sapxep" value="sắp xếp" onclick="sapxep()" />
  14.  <input type="button" name="timkiem" value="tìm Kiếm" onclick="seach()" /><p/>
  15. Mảng đã nhập <input id="hienthi" type="text" disabled="disabled" name="hienthi" />
  16.  <script>
  17.  a=new Array(100);
  18.     function themvao()
  19.     {
  20.        
  21.         document.getElementById("thu").value=eval(document.getElementById("thu").value)+1;
  22.         gt=parseInt(document.getElementById("gt").value);
  23.         a.push(gt);
  24.         document.getElementById("hienthi").value=document.getElementById("hienthi").value+gt+" ";
  25.         document.getElementById("gt").select();
  26.        
  27.     }
  28.     function sapxep()
  29.     {
  30.             document.getElementById("hienthi").value="";
  31.             a.sort()
  32.             for( var i in a)
  33.             {
  34.                     document.getElementById("hienthi").value=document.getElementById("hienthi").value+a[i]+" ";
  35.             }
  36.     }
  37.    
  38.  </script>
  39. </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement