Advertisement
giangnhauqe

baif 1

Oct 27th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.81 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.  <style>
  8.     :hover
  9. {
  10.         border:#F00;
  11.         border-style:inset;
  12. }
  13.  #hienthi{
  14.      width:100%;
  15.      height:100px;
  16.  }
  17.  </style>
  18. <body id="bang">
  19. <table border="0" width="900" >
  20.  <tr><h1 align="center" id="1"> Nhập và sắp xếp mảng </h1></tr>
  21.  <tr>
  22.  <td>Nhập phần tử thứ </td>
  23.  <td colspan="3"><input id="thu" name="pt" value="1" disabled="disabled" pattern="[0-9]*" type="text" /><p/></td>
  24.  </tr>
  25.  <tr>
  26.   <td>  Giá trị </td>
  27.   <td colspan="3"> <input id="gt" name="gt" pattern="[0-9]*" type="text" /><p/></td>
  28.   <tr>
  29.   <td>
  30.   </td>
  31.  <td><input type="button" name="them" value="thêm vào mảng" onclick="themvao()" /></td>
  32.  <td><input type="button" name="sapxep" value="sắp xếp" onclick="sapxep()" /></td>
  33.  <td><input type="button" name="timkiem" value="tìm Kiếm" onclick="search()" /></td>
  34. </tr>
  35. <tr>
  36. <td>Mảng đã nhập </td>
  37. <td colspan="3"><textarea rows="4" cols="45" name="mang" id="hienthi" ></textarea></td>
  38.  </tr>
  39.  <script>
  40.  a=new Array(100);
  41.  ttsx=false
  42.         function themvao()
  43.         {
  44.                
  45.                 document.getElementById("thu").value=eval(document.getElementById("thu").value)+1;
  46.                 gt=parseInt(document.getElementById("gt").value);
  47.                 a.push(gt);
  48.                 document.getElementById("hienthi").value=document.getElementById("hienthi").value+gt+" ";
  49.                 document.getElementById("gt").select();
  50.                
  51.         }
  52.         function sapxep()
  53.         {
  54.                         document.getElementById("hienthi").value="";
  55.                         a.sort()
  56.                         if(ttsx)
  57.                             a.reverse();
  58.                         ttsx=!ttsx
  59.                         for( var i in a)
  60.                         {
  61.                                         document.getElementById("hienthi").value=document.getElementById("hienthi").value+a[i]+" ";
  62.                         }
  63.         }
  64.         function search()
  65.         {
  66.                 var solan=0;
  67.                 tim=prompt("nhập giá trị cần tìm","")
  68.                     for(var i in a)
  69.                     {
  70.                         if(a[i]==tim)
  71.                         {
  72.                             solan++;
  73.                         }
  74.                     }
  75.                     if(solan=0)
  76.                     {
  77.                         document.getElementById("hienthi").value= "không có phần tử này";
  78.                     }
  79.                     else
  80.                     {
  81.                         document.getElementById("hienthi").value=" tim thay phan tu can tim" + solan  +"\n";
  82.                         for(var i in a)
  83.                         {
  84.                             if(a[i]==tim)
  85.                             {
  86.                                 document.getElementById("hienthi").value=document.getElementById("hienthi").value+ "vi tri suat hien" + i + "\n";
  87.                             }
  88.                         }
  89.                     }
  90.         }
  91.        
  92.  </script>
  93.  </table>
  94. </body>
  95. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement