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

WBOY
Release: 2016-06-24 11:23:02
Original
1138 people have browsed it

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>
Copy after login
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!