我试图循环属性的每一个遍历,如果它匹配,它将替换DOM的内部HTML。对于这个例子,我试图替换数据产品=“动量-短片-2-0”内部HTML,这是我在屏幕截图中突出显示的<h2>Momentum Shorts 2.0 NEW</h2>内容到<div> class="compare-main" </div>中的内容。
这就是我现在的代码,但我被困住了..它不断地返回给我最后一项的奇异值。
<script>
jQuery( document ).ready(function() {
$( ".compare-filter-item" ).click(function() {
var selected_data_product = $(this).attr("data-product");
$(".compare-all .compare-products [data-product='" + selected_data_product + "']").each(function(){
new_html = $(this).html();
$(".compare-main .compare-products [data-product='" + selected_data_product + "']").each(function(){
$(this).html(new_html);
})
});
});
})
</script>

问题:

发布于 2022-03-18 04:36:36
<script>
jQuery( document ).ready(function() {
$( ".compare-filter-item" ).click(function() {
var selected_data_product = "momentum-shorts-2-0";
$(".compare-main .compare-products [data-product='" + selected_data_product + "']").each(function(){
$(this).find("h2").text("Momentum Shorts 2.0");
});
});
})
</script>我试着理解您的需求,下面是解决方案,看看它是否有用。
https://stackoverflow.com/questions/71522347
复制相似问题