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>
- <style>
- :hover
- {
- border:#F00;
- border-style:inset;
- }
- #hienthi{
- width:100%;
- height:100px;
- }
- </style>
- <body id="bang">
- <table border="0" width="900" >
- <tr><h1 align="center" id="1"> Nhập và sắp xếp mảng </h1></tr>
- <tr>
- <td>Nhập phần tử thứ </td>
- <td colspan="3"><input id="thu" name="pt" value="1" disabled="disabled" pattern="[0-9]*" type="text" /><p/></td>
- </tr>
- <tr>
- <td> Giá trị </td>
- <td colspan="3"> <input id="gt" name="gt" pattern="[0-9]*" type="text" /><p/></td>
- <tr>
- <td>
- </td>
- <td><input type="button" name="them" value="thêm vào mảng" onclick="themvao()" /></td>
- <td><input type="button" name="sapxep" value="sắp xếp" onclick="sapxep()" /></td>
- <td><input type="button" name="timkiem" value="tìm Kiếm" onclick="search()" /></td>
- </tr>
- <tr>
- <td>Mảng đã nhập </td>
- <td colspan="3"><textarea rows="4" cols="45" name="mang" id="hienthi" ></textarea></td>
- </tr>
- <script>
- a=new Array(100);
- ttsx=false
- function themvao()
- {
- document.getElementById("thu").value=eval(document.getElementById("thu").value)+1;
- gt=parseInt(document.getElementById("gt").value);
- a.push(gt);
- document.getElementById("hienthi").value=document.getElementById("hienthi").value+gt+" ";
- document.getElementById("gt").select();
- }
- function sapxep()
- {
- document.getElementById("hienthi").value="";
- a.sort()
- if(ttsx)
- a.reverse();
- ttsx=!ttsx
- for( var i in a)
- {
- document.getElementById("hienthi").value=document.getElementById("hienthi").value+a[i]+" ";
- }
- }
- function search()
- {
- var solan=0;
- tim=prompt("nhập giá trị cần tìm","")
- for(var i in a)
- {
- if(a[i]==tim)
- {
- solan++;
- }
- }
- if(solan=0)
- {
- document.getElementById("hienthi").value= "không có phần tử này";
- }
- else
- {
- document.getElementById("hienthi").value=" tim thay phan tu can tim" + solan +"\n";
- for(var i in a)
- {
- if(a[i]==tim)
- {
- document.getElementById("hienthi").value=document.getElementById("hienthi").value+ "vi tri suat hien" + i + "\n";
- }
- }
- }
- }
- </script>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement