javascript - 如何更改 document.getClassName 调用中的所有项目值(没有它只使用第一个元素值)
问题描述
我正在尝试更改页面上的单个产品价格,因为由于我使用的电子商务平台,编码都搞砸了。我需要在一个 £ 符号上分开,这似乎适用于单个项目
我尝试通过使用 getElementID 来改变我这样做的方式,但由于电子商务平台的运作方式,这并不好,而且我无法更改任何后端 stff。
<div class="products-price">
<!--START: ITEMPRICE-->
<span class="subfix">[ITEMPRICE]</span>
<!--END: ITEMPRICE-->
</div>
jQuery(document).ready(function () {
var total = document.getElementsByClassName('subfix')
for (i = 0; i < total.length; i++) {
total[i].textContent.split('£')[1];
}
});
解决方案
您还必须将文本设置为该元素
jQuery(document).ready(function() {
var total = document.getElementsByClassName('subfix')
for (i = 0; i < total.length; i++) {
total[i].textContent=total[i].textContent.split('£')[1];
}
});
<div class="products-price">
<span class="subfix"> </span>
</div>
推荐阅读
- python - 使用一个类创建的两个不同对象共享相同的内存
- python - 赋值前引用的局部变量“n”。闭包
- c# - 在 blazor 中使用带有身份验证的 WebAPI
- firebase - 用于列表构建的 Flutter 中的 Firestore 嵌套查询
- javascript - API 请求在 PostMan 中有效,但在 AJAX 中无效
- mysql - 问:Fedora 30 上的 MariaDB 安装问题
- python - ModuleNotFoundError:没有名为“support_functions”的模块
- python - 使用python添加csv文件的列
- javascript - 如何避免 Vue.JS/Axion 返回 undefined 而响应代码为 200?
- python - x = Concatenate(axis=1)([out1, out2, out3, out4]) ValueError: A `Concatenate` 层需要具有匹配形状的输入,但 concat 轴除外