如何用JS更改或替换div、tag、row下的文本。这是代码:
$(document).ready(function() {
$("div .row .col-sm-4").each(function() {
if ($(this).text() == "Registrant ID:") {
$(this).text().replace("Registrant Number:");
}
});
});
此处为 HTML 代码:
<div class="row">
<div class="col-sm-4">Registrant ID:</div>
</div>
我这里用的是javascript,好像没有效果。
最佳答案
您可以使用 .html()
代替 .text().replace()
并更改 div 选择器。
$(document).ready(function() {
$(".col-sm-4").each(function() {
if ($(this).text() == "Registrant ID:") {
$(this).html("Registrant Number:");
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="col-sm-4">Registrant ID:</div>
</div>
关于javascript - 如何使用javascript更改或替换div、row下的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45836075/