改善网址更改-jQuery

时间:2018-10-08 20:23:14

标签: javascript jquery

我学习js和jquery,我想知道如何改进波纹管代码?一切正常,但我认为它可以使编码更有效和更智能。这是更新URL的更好方法吗?

// Selected Attributes
var selected_product_size = ('size_5x5');
var selected_product_color = ('color_01');  


// Default Product Preview
$('.product__live-preview.front').css('background-image', 'url(./assets/img/products/'+ selected_product_size +'/'+ selected_product_color +'/front.png)');
$('.product__live-preview.back').css('background-image', 'url(./assets/img/products/' + selected_product_size + '/'+ selected_product_color +'/back.png)');

// Size Select
$('#product-tab-size input').on('click', function () {
    $('#product-tab-size input').not(this).removeClass('checked');
    $(this).toggleClass('checked');

    selected_product_size = $(this).attr('id');

    $('.product__live-preview.front').css('background-image', 'url(./assets/img/products/'+ selected_product_size +'/'+ selected_product_color +'/front.png)');
    $('.product__live-preview.back').css('background-image', 'url(./assets/img/products/' + selected_product_size + '/'+ selected_product_color +'/back.png)');
});

// Color Select
$('#product-tab-color input').on('click', function () {
    $('#product-tab-color input').not(this).removeClass('checked');
    $(this).toggleClass('checked');

    selected_product_color = $(this).attr('id');

    $('.product__live-preview.front').css('background-image', 'url(./assets/img/products/'+ selected_product_size +'/'+ selected_product_color +'/front.png)');
    $('.product__live-preview.back').css('background-image', 'url(./assets/img/products/' + selected_product_size + '/'+ selected_product_color +'/back.png)');
});

0 个答案:

没有答案