close

<div>
<p>
哥林多前書13:4-5哥林多前書13:4-5哥林多前書13:4-5哥林多前書13:4-5哥林多前書13:4-5哥林多前書13:4-5哥林多前書13:4-5哥林多前書13:4-5哥林多前書13:4-5哥林多前書13:4-5
</p>
<div>

.someclass {
color: red;
}

var yourstring="多";

$('p:contains('+yourstring+')', document.body).each(function(){
console.log(this);
$(this).html($(this).html().replace(
new RegExp(yourstring, 'g'), '<span class="someclass">'+yourstring+'</span>'
));
});

 

http://stackoverflow.com/questions/13780784/jquery-find-and-change-style-of-a-string

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 amychang2014 的頭像
    amychang2014

    工作需要筆記

    amychang2014 發表在 痞客邦 留言(0) 人氣()