<script type="text/javascript">
//var array = [[‘红色‘, ‘黑色‘, ‘白色‘], [‘小号‘, ‘中号‘, ‘加大‘], [‘男‘, ‘女‘]];
var array = [[‘5:红色‘], [‘7:M‘, ‘8:L‘]];
var results = new Array(); //创建一个数组
var len = array.length;
var indexs = {};
$(document).ready(function () {
GetResults(-1);
$("#cou").html("共有" + results.length + "种组合;<br/>");
for (var a = 0; a < results.length; a++)
{
$("#list").append("<li>" + results[a] + "</li>");
}
});
function GetResults(start) {
start++;
if (start > len - 1) {
return;
}
if (!indexs[start]) {
indexs[start] = 0;
}
if (!(array[start] instanceof Array)) {
array[start] = [array[start]];
}
for (indexs[start] = 0; indexs[start] < array[start].length; indexs[start]++) {
GetResults(start);
if (start == len - 1) {
var temp = [];
for (var i = len - 1; i >= 0; i--) {
if (!(array[start - i] instanceof Array)) {
array[start - i] = [array[start - i]];
}
temp.push(array[start - i][indexs[start - i]]);
}
results.push(temp);
}
}
}
</script>