/** * * * 生成需要的js循环。递归调用 PHP * * 形式参考 ( 2个规格) * $('input[type="checkbox"]').click(function(){ * str = ''; * for (var i=0; i<spec_group_checked[0].length; i++ ){ * td_1 = spec_group_checked[0][i]; * for (var j=0; j<spec_group_checked[1].length; j++){ * td_2 = spec_group_checked[1][j]; * str += '<tr><td>'+td_1[0]+'</td><td>'+td_2[0]+'</td><td><input type="text" /></td><td><input type="text" /></td><td><input type="text" /></td>'; * } * } * $('table[class="spec_table"] > tbody').empty().html(str); * }); */ function recursionSpec($len,$sign) { if($len < $sign){ echo "for (var i_".$len."=0; i_".$len."<spec_group_checked[".$len."].length; i_".$len."++){td_".(intval($len)+1)." = spec_group_checked[".$len."][i_".$len."];\n"; $len++; recursionSpec($len,$sign); }else{ echo "var tmp_spec_td = new Array();\n"; for($i=0; $i< $len; $i++){ echo "tmp_spec_td[".($i)."] = td_".($i+1)."[1];\n"; } echo "tmp_spec_td.sort(function(a,b){return a-b});\n"; echo "var spec_bunch = 'i_';\n"; for($i=0; $i< $len; $i++){ echo "spec_bunch += tmp_spec_td[".($i)."];\n"; } echo "str += '<input type=\"hidden\" name=\"spec['+spec_bunch+'][goods_id]\" nc_type=\"'+spec_bunch+'|id\" value=\"\" />';"; for($i=0; $i< $len; $i++){ echo "if (td_".($i+1)."[2] != null) { str += '<input type=\"hidden\" name=\"spec['+spec_bunch+'][color]\" value=\"'+td_".($i+1)."[1]+'\" />';}"; echo "str +='<td><input type=\"hidden\" name=\"spec['+spec_bunch+'][sp_value]['+td_".($i+1)."[1]+']\" value=\"'+td_".($i+1)."[0]+'\" />'+td_".($i+1)."[0]+'</td>';\n"; } echo "str +='<td><input class=\"text price\" type=\"text\" name=\"spec['+spec_bunch+'][marketprice]\" data_type=\"marketprice\" nc_type=\"'+spec_bunch+'|marketprice\" value=\"\" /><em class=\"add-on\"><i class=\"icon-renminbi\"></i></em></td><td><input class=\"text price\" type=\"text\" name=\"spec['+spec_bunch+'][price]\" data_type=\"price\" nc_type=\"'+spec_bunch+'|price\" value=\"\" /><em class=\"add-on\"><i class=\"icon-renminbi\"></i></em></td><td><input class=\"text stock\" type=\"text\" name=\"spec['+spec_bunch+'][stock]\" data_type=\"stock\" nc_type=\"'+spec_bunch+'|stock\" value=\"\" /></td><td><input class=\"text stock\" type=\"text\" name=\"spec['+spec_bunch+'][alarm]\" data_type=\"alarm\" nc_type=\"'+spec_bunch+'|alarm\" value=\"\" /></td><td><input class=\"text sku\" type=\"text\" name=\"spec['+spec_bunch+'][sku]\" nc_type=\"'+spec_bunch+'|sku\" value=\"\" /></td></tr>';\n"; for($i=0; $i< $len; $i++){ echo "}\n"; } } }
function recursionSpec($len, $sign) { if ($len < $sign) { echo "for (var i_" . $len . "=0; i_" . $len . "<spec_group_checked[" . $len . "].length; i_" . $len . "++){td_" . (intval($len) + 1) . " = spec_group_checked[" . $len . "][i_" . $len . "];\n"; $len++; recursionSpec($len, $sign); } else { echo "var spec_bunch = 'i_';\n"; for ($i = 0; $i < $len; $i++) { echo "spec_bunch += td_" . ($i + 1) . "[1];\n"; } for ($i = 0; $i < $len; $i++) { echo "str +='<td><input type=\"hidden\" name=\"spec['+spec_bunch+'][sp_value]['+td_" . ($i + 1) . "[1]+']\" value='+td_" . ($i + 1) . "[0]+' />'+td_" . ($i + 1) . "[0]+'</td>';\n"; } echo "str +='<td><input class=\"text\" type=\"text\" name=\"spec['+spec_bunch+'][price]\" data_type=\"price\" nc_type=\"'+spec_bunch+'|price\" value=\"\" /></td><td><input class=\"text\" type=\"text\" name=\"spec['+spec_bunch+'][stock]\" data_type=\"stock\" nc_type=\"'+spec_bunch+'|stock\" value=\"\" /></td><td><input class=\"text\" type=\"text\" name=\"spec['+spec_bunch+'][sku]\" nc_type=\"'+spec_bunch+'|sku\" value=\"\" /></td></tr>';\n"; for ($i = 0; $i < $len; $i++) { echo "}\n"; } } }