
获得徽章 0
- 1.====JS:四舍五入到千位,不足千位的四舍五入到百位===
function roundToThousands(num) {
if (typeof num === "number" && !Number.isNaN(num)) {
if (num >= 1000) {
return Math.round(num / 1000) * 1000
} else if (num > 0) {
return Math.round(num / 100) * 100
} else {
return 0
}
} else {
return num
}
}
2.====JS:计算文本高度===
function getTextHeight() {
let p = document.createElement("p")
p.textContent = "文本内容"
if (window.getComputedStyle) {
document.body.appendChild(p)
let height = parseFloat(window.getComputedStyle(p).height)
document.body.removeChild(p)
return height
} else {
return null
}
}展开评论1