<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><title>价格显示示例</title><style>.small {font-size: 0.7em; /* 设置较小的字体大小 */color:red;}#price{color:red;}</style>
</head>
<body>
<p id="price">¥70.00</p>
<script>// 获取价格元素const priceElement = document.getElementById("price");// 获取价格字符串const priceText = priceElement.innerText;// 使用正则表达式匹配价格部分const priceParts = priceText.match(/(¥)(\d+)(\.\d+)/);if (priceParts) {// 重建价格HTMLconst formattedPrice = `<span class="small">${priceParts[1]}</span>${priceParts[2]}<span class="small">${priceParts[3]}</span>`;// 更新内联HTMLpriceElement.innerHTML = formattedPrice;}
</script>
</body>
</html>