使用 $(document).ready(function() 更改标签的文本



f我正在尝试更改在此显示"副本"的标签

$(document).ready(function() {
$('.availableLabel.copiedCountLabel').text("Available in Region");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="availableDiv0" class="availableDiv copiesCountSection">
<span class="availableLabel copiesCountLabel">Copies: </span>
<span style="display:inline-block;" name="smallSearchingGif" id="copiesCountNumber1040573" class="availableNumber copiesCountNumber">
2
</span>
</span>

我将如何将文本"副本"更改为"在区域中可用"。

也许,这个类是错误的?

.copiedCountLabel

尝试在 html 代码中使用类 .copyiesCountLabel:

$(document).ready(function(){
$('.availableLabel.copiesCountLabel').text("Available in Region");
});

您的选择器中有拼写错误。 你想获取副本CountLabel,但试图获取副本dCountLabel

还要考虑将id属性用于此类唯一类。

如果要选择具有两个类的标签,则需要将选择器一起写入,中间没有空格。

在您的情况下,它是标签类.availableLabel.copiesCountLabel

$(document).ready(function() {
$('.availableLabel.copiesCountLabel').text("Available in Region ");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="availableDiv0" class="availableDiv copiesCountSection"><span class="availableLabel copiesCountLabel">Copies: </span><span style="display:inline-block;" name="smallSearchingGif" id="copiesCountNumber1040573" class="availableNumber copiesCountNumber">2</span></span>

一个建议是,如果这是唯一需要更改的元素,那么最好使用id而不是class

最新更新