生成sku js

  <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>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。