jQuery-一个有效的代码编写问题

时间:2019-01-16 16:38:39

标签: jquery performance

我正在向每个产品页面添加HTML块。除了我要更改图像外,每种产品的HTML都相似。

现在,我要为每种产品重复整个HTML块,我宁愿只是添加该代码,然后注入新图像而不是每次都重复HTML。

是否有解决此问题的好方法?我需要将HTML添加到每个产品页面,但实际上我只需要在每个HTML块中切换图像(gi-chart和gi-chart-2)。

感谢您的任何投入,我在编写jQuery方面相对较新,并且希望确保以最佳方式进行操作。

这是我到目前为止所拥有的

$( "body" ).each(function() {

    if ( $( this ).hasClass( "product-fruit-nuts-superfood-with-baobab" ) ) {

        $( this )
        $(".eltdf-accordion-holder").each(function() {
        $(this).append('<div class="gi-chart-wrap"><span class="eltdf-title-holder reviews_tab ui-accordion-header ui-state-default ui-corner-all" role="tab" id="ui-id-3" aria-controls="ui-id-4" aria-selected="false" aria-expanded="false" tabindex="-1"><span class="eltdf-accordion-mark"><span class="eltdf_icon_plus icon_plus"></span><span class="eltdf_icon_minus icon_minus-06"></span></span><span class="eltdf-tab-title">GI Chart</span></span></div><div class="eltdf-accordion-content ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" id="ui-id-4" aria-labelledby="ui-id-3" role="tabpanel" aria-hidden="true" style="display: none;"><img src="/wp-content/uploads/2019/01/gi-chart.png" alt="GI Chart" /></div></div>');

    });    

    } else if ( $( this ).hasClass( "product-dark-chocolate-mandarin" ) ) {
        $( this )
        $(".eltdf-accordion-holder").each(function() {
        $(this).append('<div class="gi-chart-wrap"><span class="eltdf-title-holder reviews_tab ui-accordion-header ui-state-default ui-corner-all" role="tab" id="ui-id-3" aria-controls="ui-id-4" aria-selected="false" aria-expanded="false" tabindex="-1"><span class="eltdf-accordion-mark"><span class="eltdf_icon_plus icon_plus"></span><span class="eltdf_icon_minus icon_minus-06"></span></span><span class="eltdf-tab-title">GI Chart</span></span></div><div class="eltdf-accordion-content ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" id="ui-id-4" aria-labelledby="ui-id-3" role="tabpanel" aria-hidden="true" style="display: none;"><img src="/wp-content/uploads/2019/01/gi-chart-2.png" alt="GI Chart" /></div></div>');
    });

    }
});

这是网站:https://www.solonutrition.com/product/dark-chocolate-mandarin/

1 个答案:

答案 0 :(得分:1)

尝试一下:

ImportError: 
Importing the multiarray numpy extension module failed.
Most likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: DLL load failed: Das angegebene Modul wurde nicht gefunden.

});