我可以在我的网上商店中删除所有“.0000”外观吗?

问题描述

我正在开发一个电子商务网站,其中 500 种产品 + 规格是从 CSV 文件自动导入的。

不幸的是,有些规格除了主编号外还有“.0000”。 例如:

产品 1:

  • 深度:40.0000
  • 身高:78.0000
  • 宽度:125.0000

产品 2:

  • 深度:20.0000
  • 高度:42.0000
  • 怀特:200.0000

我希望数字是“圆形”(40 / 78 / 125 / 20 / 42 / 200)

我是 CSS/JS 的新手,但我能够找到可以添加自定义 CSS 的部分:)

是否可以用代码隐藏所有“.0000”?

解决方法

使用 parseInt 内置函数将数字四舍五入为绝对一或使用 parseFloat 将数字四舍五入:

const number = parseInt(40.0000);
alert(number)

,

您可以使用 parseint 方法..parseInt(value)

,

试试这个,这不是最好的方法,因为它会测试你网站上的每个元素,它会搜索包含 .0000 的字符串,然后用空字符串替换它

document.addEventListener("DOMContentLoaded",function(){
[...document.querySelectorAll("*")]//query selector for all the elements in DOM
.filter(e => e.childNodes && [...e.childNodes].find(n => n.nodeValue?.match(".0000")))//filter all the elements that contains .0000
.forEach(element => element.innerText = (element.innerText.replace(/.0000/,"")));//replace it with empty string
});
<ul>
<li>Diepte: 40.0000</li>
<li>Hoogte: 78.0000</li>
<li>Breedte: 125.0000</li>
</ul>