復制代碼 代碼如下:
<!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=gb2312" />
<title>楊氏矩陣查找</title>
</head>
<body>
<script language="javascript">
function xunhuan()
{
var m = parseInt(document.getElementsByTagName("input")[0].value)||document.getElementsByTagName("input")[0].getAttribute("value");
var n = parseInt(document.getElementsByTagName("input")[1].value)||document.getElementsByTagName("input")[1].getAttribute("value");
var t = parseInt(document.getElementsByTagName("input")[2].value)||document.getElementsByTagName("input")[2].getAttribute("value");
if(m >= 1&&n <= 1000&&t >= 1&&t <= 1000000)
{
var num = 2;
for(var x = 0;x < m;x++)
{
for(var y = 0;y < n;y++)
{
document.write((num++)+" ");
}
document.write("<br/>");
}
var a=new Array();
for(var e = m*n+1;e > 1; e--)
{
a.splice(0,0,e)
}
chazhao(a,t);
}
else
{
alert("不符合要求,請重新輸入");
}
}
function chazhao(a,number)
{
document.write(isCon(a, number));
function isCon(a, number)
{
for(var i=0; i<a.length; i++)
{
if(a[i] === number)
{
return String(true);
}
}
return String(false);
}
}
</script>
<form>
<p>矩陣行數:<input type="text" name="矩陣行數" value=3 /> 矩陣列數:<input type="text" name="矩陣列數" value=3 /></p>
<p>查詢數字:<input type="text" name="查詢數字" value=1 /></p>
<input type="button" onclick="xunhuan()" value="數組" />
</form>
</body>
</html>