<!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>shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ *//* ]]> */
</style>
<script type="text/javascript">
/*<![CDATA[*/
if (navigator.appName=="Microsoft Internet Explorer")
{
//最大化窗口
self.moveTo(-5,-5)
self.resizeTo(screen.availWidth +8,screen.availHeight+8)
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
/*]]*/
</script>
</head>
<body>
<script type="text/javascript">
/*<![CDATA[*/
var Ar = [0, 1, 2, 3, 4];
var Ar1 = [2, 3, 4, 5, 6];
var Ar2 = [4, 5, 6, 7, 8];
var Ar3 = [4, 5, 6, 7, 8, 9, 10];
document.write("Ar: ", Ar, "<br/>");
document.write("Ar1: ", Ar1, "<br/>");
document.write("Ar2: ", Ar2, "<br/>");
document.write("Ar3: ", Ar3, "<br/>");
document.write("<hr/>");
document.write("fGetTheSame(Ar):", fGetTheSame(Ar), "<hr/>");
document.write("fGetTheSame(Ar, Ar1):", fGetTheSame(Ar, Ar1), "<hr/>");
document.write("fGetTheSame(Ar1, Ar2, Ar3):", fGetTheSame(Ar1, Ar2, Ar3), "<hr/>");
document.write("fGetTheSame(Ar, Ar1, Ar2, Ar3):", fGetTheSame(Ar, Ar1, Ar2, Ar3), "<hr/>");
function fGetTheSame()
{// shawl.qiu code : return Array
var Arg = arguments;
var Len = Arg.length;
if(Len<1) throw new Error("参数错误, 必须最少为一个数组!");
var TempLen = Len;
while(--TempLen>-1) if(Arg[TempLen].constructor!=Array) throw new Error("参数必须为数组!");
if(TempLen===1) return Arg[0];
var Ar = Arg[0].slice();
var ResultAr = [];
for(var i=0, j=Ar.length; i<j; i++)
{
var HasAr = [];
for(var I=1; I<Len; I++)
{
for(var J=0, K=Arg[I].length; J<K; J++)
{
if(Ar[i]===Arg[I][J])
{
HasAr.push(true);
break;
}
}
}
if(HasAr.length===Len-1) ResultAr.push(Ar[i]);
}
return ResultAr;
} // end function fGetTheSame()
/*]]*/
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ *//* ]]> */
</style>
<script type="text/javascript">
/*<![CDATA[*/
if (navigator.appName=="Microsoft Internet Explorer")
{
//最大化窗口
self.moveTo(-5,-5)
self.resizeTo(screen.availWidth +8,screen.availHeight+8)
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
/*]]*/
</script>
</head>
<body>
<script type="text/javascript">
/*<![CDATA[*/
var Ar = [0, 1, 2, 3, 4];
var Ar1 = [2, 3, 4, 5, 6];
var Ar2 = [4, 5, 6, 7, 8];
var Ar3 = [4, 5, 6, 7, 8, 9, 10];
document.write("Ar: ", Ar, "<br/>");
document.write("Ar1: ", Ar1, "<br/>");
document.write("Ar2: ", Ar2, "<br/>");
document.write("Ar3: ", Ar3, "<br/>");
document.write("<hr/>");
document.write("fGetTheSame(Ar):", fGetTheSame(Ar), "<hr/>");
document.write("fGetTheSame(Ar, Ar1):", fGetTheSame(Ar, Ar1), "<hr/>");
document.write("fGetTheSame(Ar1, Ar2, Ar3):", fGetTheSame(Ar1, Ar2, Ar3), "<hr/>");
document.write("fGetTheSame(Ar, Ar1, Ar2, Ar3):", fGetTheSame(Ar, Ar1, Ar2, Ar3), "<hr/>");
function fGetTheSame()
{// shawl.qiu code : return Array
var Arg = arguments;
var Len = Arg.length;
if(Len<1) throw new Error("参数错误, 必须最少为一个数组!");
var TempLen = Len;
while(--TempLen>-1) if(Arg[TempLen].constructor!=Array) throw new Error("参数必须为数组!");
if(TempLen===1) return Arg[0];
var Ar = Arg[0].slice();
var ResultAr = [];
for(var i=0, j=Ar.length; i<j; i++)
{
var HasAr = [];
for(var I=1; I<Len; I++)
{
for(var J=0, K=Arg[I].length; J<K; J++)
{
if(Ar[i]===Arg[I][J])
{
HasAr.push(true);
break;
}
}
}
if(HasAr.length===Len-1) ResultAr.push(Ar[i]);
}
return ResultAr;
} // end function fGetTheSame()
/*]]*/
</script>
</body>
</html>
解决方案 »
- 在JS中如何遍历一个数组,并且比较最中最大的值,
- HTML源代码替换
- ie8关闭弹出窗口后报错,急。
- JS在html页面之间的传值和调用JS方法
- 热区颜色问题
- 各位大侠:请教个问题JS获取路径问题
- js ajax 里访问不了节点列表的第i个元素
- 检测输入框内字符串长度
- 怎样把"where or charindex('ddd',spbm) or charindex('eee',gnzz)"最前面的or替换掉啊?javascript里没有replaceFirst函数??
- 如何删除select的option?
- 请大家一定要帮我这个忙.
- 【求助】如何把一个div从一个浏览器窗口拖到另外一个浏览器窗口里。
<!--
var a1 = new Array(1,2,3,6,7,8);
var a2 = new Array(4,5,6);
var a3 = new Array(3,6,7);
var a0 = new Array(a1, a2, a3);
var list = new Object();
for (var i=0; i<a0.length; i++)
{
for (var j=0; j<a0[i].length; j++)
{
if (list[a0[i][j]] == undefined)
{
list[a0[i][j]] = 1;
}
else
{
list[a0[i][j]] = list[a0[i][j]] + 1;
}
}
}for (var i in list)
{
if (list[i]==a0.length)
{
alert("Common number is " + i);
}
}
//-->
</script>
for(n=0;n<fd1.length;n++){
explode(fd1[n],"@",fd3); //explode的作用是將fd1[n]中的子符以@為分割,轉換成數組
}
這樣的話我怎嚜將fd3放入fGetTheSame()作為參數呢?
//<![CDATA[
var ar=[];
for(var i=0; i<5; ar[i]=i++);
document.write(ar,'<p/>');
document.write(fApl.apply(null,ar),'<p/>');
document.write(fArg(ar),'<p/>');
function fApl(){
if(arguments.length<1)return false;
var sum=0;
for(var i=0, len=arguments.length; i<len; i++)sum+=arguments[i];
return sum;
}
function fArg(ar){
if(ar.length<1)return false;
var sum=0;
for(var i=0, len=ar.length; i<len; i++)sum+=ar[i];
return sum;
}
//]]>
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ *//* ]]> */
</style>
<script type="text/javascript">
/*<![CDATA[*/
if (navigator.appName=="Microsoft Internet Explorer")
{
//最大化窗口
self.moveTo(-5,-5)
self.resizeTo(screen.availWidth +8,screen.availHeight+8)
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
/*]]*/
</script>
</head>
<body>
<script type="text/javascript">
/*<![CDATA[*/
var Ar = [0, 1, 2, 3, 4];
var Ar1 = [2, 3, 4, 5, 6];
var Ar2 = [4, 5, 6, 7, 8];
var Ar3 = [4, 5, 6, 7, 8, 9, 10];document.write("Ar: ", Ar, "<br/>");
document.write("Ar1: ", Ar1, "<br/>");
document.write("Ar2: ", Ar2, "<br/>");
document.write("Ar3: ", Ar3, "<br/>");
document.write("<hr/>");document.write("fGetTheSame(Ar):", fGetTheSame(Ar), "<hr/>");
document.write("fGetTheSame(Ar, Ar1):", fGetTheSame(Ar, Ar1), "<hr/>");
document.write("fGetTheSame(Ar1, Ar2, Ar3):", fGetTheSame(Ar1, Ar2, Ar3), "<hr/>");
document.write("fGetTheSame(Ar, Ar1, Ar2, Ar3):", fGetTheSame(Ar, Ar1, Ar2, Ar3), "<hr/>");function fGetTheSame() {// shawl.qiu code : return Array
var arg = arguments, len = i = arg.length, a = [];
if (len < 1) throw new Error("参数错误, 必须最少为一个数组!");
else while (-- i > -1) if (arg[i].constructor != Array) throw new Error("参数必须为数组!");
(',' + Array.apply(null, arg).join(",").split(",").sort().join(",")).replace(new RegExp("(,([0-9]+))\\1{" + (len - 1) + "}", "g"), function ($a, $b, $c) {
return a[a.length] = $c;
});
return a;
} // end function fGetTheSame()
/*]]*/
</script>
</body>
</html>
var strA="a@g^a@b@g^h@g"
var fd1=new Array();
var fd2=new Array();
var fd3=new Array();
var newa=new Array();
var counter=0;
explode(strA,"^",fd1);//explode的作用時:fd1=(a@g,a@b@g,h@g)且是一個Array
for(n=0;n<fd1.length;n++){
explode(fd1[n],"@",fd2);
fGetTheSame(fd2);
}
如果這樣執行fGetTheSame,並不能等到交集,
我本想得到:
var fd2-1=(a,g); var fd2-2=(a,b,g); var fd2-3=(h,g);
然後執行fGetTheSame(fd2-1,fd2-2,fd2-3)
这个意思?
可是怎嚜把這個數組作為fGetTheSame()的參數呢
多謝高手幫忙!