<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<a href="#" id="test">test</a>
<br/>
<div id="result">
</div>
<script>
$(function(){
$("#test").click(function(){
$("#result").html("");
var arr = new Array();
var a1 = new Array("35","36","37","38");
var a2 = new Array("红","蓝","黑");
var a3 = new Array("大","中");
var a4 = new Array("abc","cde");
var a5 = new Array("一个星","二个星");
var a6= new Array("3个月","5个月");
arr.push(a1);
arr.push(a2);
arr.push(a3);
arr.push(a4);
arr.push(a5);
arr.push(a6);
//在已知的情况下是如下
// for ( var i=0; i< a1.length; i++) {
// for ( var j=0; j< a2.length; j++) {
// for ( var k=0; k< a3.length; k++) {
// $("#result").html($("#result").html() + "<br/>" + a1[i] + " " + a2[j] + " " + a3[k]);
// }
//
// }
// }
//在不知arr的长度属性时
forAttr(arr,0,new Array());
});
})
/**
*attr:全部属性组
*curr_arr_index:代表当前属性集的索引
*curr:代表累计之前的属性数组
*/
function forAttr(attr,curr_arr_index,curr){
for(var x=0;x<attr[curr_arr_index].length;x++){
if( curr_arr_index >= attr.length-1){
var str = "";
for(y in curr){
str = str + " " +curr[y];
}
str = str + " " + attr[curr_arr_index][x];
$("#result").html($("#result").html() + "<br/>" +str);
}else{
curr[curr_arr_index] = attr[curr_arr_index][x];
forAttr(attr,curr_arr_index+1,curr);
}
}
curr=null;
}
</script>
</body>
</html>
如果未知的多属性进行循环后匹配js
如果未知的多属性进行循环后匹配js
最新推荐文章于 2022-11-18 11:09:39 发布