Home >Web Front-end >HTML Tutorial >如何设置所有元字的前面都是某个样式_html/css_WEB-ITnose

如何设置所有元字的前面都是某个样式_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:23:021250browse

1元
3元 986元
8765.86元

用js配合css或者纯css设置所有的元字的前面的文字都使用class="aa"
aa里面我设置好了,字体和颜色。


之前看到过类似的代码,现在要用了找不到了


回复讨论(解决方案)

str.replace(/[\d\.]+(?=元)/g,"$&")

都添加一个span或者b标签就行了啊

str.replace(/[\d\.]+(?=元)/g,"$&")





1元 3元 986元 8765.86元

<script> <br /> <br />var str = document.getElementById("tab").outerHTML; <br />str.replace(/[\d\.]+(?=元)/g,"<span class='aa'>$&"); <br />alert(str); <br /></script>
无效啊


str.replace(/[\d\.]+(?=元)/g,"$&")





1元 3元 986元 8765.86元

<script> <br /> <br />var str = document.getElementById("tab").outerHTML; <br />str.replace(/[\d\.]+(?=元)/g,"<span class='aa'>$&"); <br />alert(str); <br /></script>
无效啊
<style>.aa{color:red}</style><table id="tab"><tr><td>1元 3元 986元 8765.86元</td></tr></table><script>var str = document.getElementById("tab").outerHTML;str=str.replace(/[\d\.]+(?=元)/g,"<span class='aa'>$&</span>");alert(str);document.getElementById("tab").outerHTML=str;</script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn