<!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" value=3 /> 矩阵列数:<input type="text" value=3 /></p>
<p>查询数字:<input type="text" value=1 /></p>
<input type="button" value="数组" />
</form>
</body>
</html>
杨氏矩阵查找的JS代码
内容版权声明:除非注明,否则皆为本站原创文章。