js 执行一段html代码,javascript - 多次执行同一段JS代码,为何只有第一段Html代码执行?...

黄舟2017-04-10 16:00:021楼

@foreach (var category in Model.Categories)

{

//-这里循环开始,比如Model.Categories里面有3组数据

@(index)F @category.Name

@foreach (var ca in category.SubCategories)

{

@ca.Name

}

All Other

//-- 这里是下面的内容

@foreach (var subca in category.SubCategories)

{

}

index++;

}

$(document).ready(function () {

/*首页的分类产品数据 */

homePageCategoriesInTabs();

$('.home-page-category-tabs .home-page-category-anchor').first().click();

});

function homePageCategoriesInTabs() {

if ($('.home-page-category-tabs').length == 0) {

return;

}

var getProductsUrl = $('.home-page-category-tabs').attr('data-get-products-url');

if (typeof getProductsUrl == 'undefined' || getProductsUrl == '') {

return;

}

$('.home-page-category-tabs .home-page-category-anchor').on('click', function () {

var currentThis = $(this);

var categoryId = currentThis.attr('data-category-id');

if (typeof categoryId == 'undefined' || categoryId == '' || categoryId == '0') {

return;

}

var categoryContentElement = $('.home-page-category-tabs .home-page-category-content[data-category-id="' + categoryId + '"]');

if (categoryContentElement.length == 0) {

return;

}

var isAlreadyLoaded = currentThis.attr('data-is-already-loaded');

if (typeof isAlreadyLoaded == 'undefined' || isAlreadyLoaded != 'true') {

currentThis.attr('data-is-already-loaded', 'true');

//$('.home-page-category-tabs .ajax-loading-overlay1').addClass('active');

$.ajax({

cache: false,

type: 'POST',

data: {

'id': categoryId

},

url: getProductsUrl

}).done(function (data) {

if (data.trim().length == 0) {

data = '

' + '@T("SevenSpikes.Themes.Urban.HomePageCategories.NoProductsFound")' + '

';

}

categoryContentElement.html(data);

// Show the selected tab, when its content is loaded

currentThis.parent().addClass('active').siblings().removeClass('active');

categoryContentElement.addClass('active').siblings('.home-page-category-content').removeClass('active');

// Ajax Cart for the selected tab

if (typeof nopAjaxCart !== "undefined" && nopAjaxCart.replaceAddToCartButtonsExternal !== undefined) {

nopAjaxCart.replaceAddToCartButtonsExternal();

}

// Quick View for the selected tab

if (typeof GetProductSelector !== "undefined" && typeof GetQuickViewButtonParentSelector !== "undefined" && typeof AddQuickViewButtons !== "undefined") {

var productSelector = GetProductSelector();

if (productSelector == "") {

return;

}

var quickViewButtonParentSelector = GetQuickViewButtonParentSelector(productSelector);

AddQuickViewButtons(productSelector, quickViewButtonParentSelector);

}

// Product Ribbons for the selected tab

if (typeof nopProductRibbons != "undefined" && nopProductRibbons.showRibbons != undefined) {

nopProductRibbons.showRibbons();

}

}).always(function () {

$('.home-page-category-tabs .ajax-loading-overlay').removeClass('active');

$('.home-page-category-tabs').trigger('homePageCategoriesProductsLoaded');

});

} else {

currentThis.parent().addClass('active').siblings().removeClass('active');

categoryContentElement.addClass('active').siblings().removeClass('active');

}

});

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值