$(function() { $.ajax({ url: ApiUrl + "/index.php?act=index", type: 'get', dataType: 'json', success: function(result) { var data = result.datas; var html = ''; $.each(data, function(k, v) { $.each(v, function(kk, vv) { switch (kk) { case 'adv_list': case 'home3': $.each(vv.item, function(k3, v3) { vv.item[k3].url = buildUrl(v3.type, v3.data); }); break; case 'home1': vv.url = buildUrl(vv.type, vv.data); break; case 'home2': case 'home4': vv.square_url = buildUrl(vv.square_type, vv.square_data); vv.rectangle1_url = buildUrl(vv.rectangle1_type, vv.rectangle1_data); vv.rectangle2_url = buildUrl(vv.rectangle2_type, vv.rectangle2_data); break; } html += template.render(kk, vv); return false; }); }); $("#main-container").html(html); $('.adv_list').each(function() { if ($(this).find('.item').length < 2) { return; } Swipe(this, { startSlide: 2, speed: 400, auto: 3000, continuous: true, disableScroll: false, stopPropagation: false, callback: function(index, elem) {}, transitionEnd: function(index, elem) {} }); }); } }); $('.search-btn').click(function(){ var keyword = encodeURIComponent($('#keyword').val()); location.href = WapSiteUrl+'/tmpl/product_list.html?keyword='+keyword; }); });