简单地说,如何使用jQuery用HTML替换精确文本?
原始文字是 View All Customer Reviews
我希望将其替换为<span class="redbutton">View All Reviews »</span>
感谢。
答案 0 :(得分:2)
<div id="_div">xxx|||View All Customer Reviews|||xxx</div>
<script>
$(function() {
var html = $('#_div').html() + '';
html = html.replace(/View All Customer Reviews/g, '<span class="redbutton">View All Reviews »</span>');
$('#_div').html(html);
});
</script>
// =================== ---- ================== /// < / p>
<a>xxx|||View All Customer Reviews|||xxx</a>
<a>yyy|||View All Customer Reviews|||yyy</a>
<a>zzz|||View All Customer Reviews|||zzz</a>
<script>
$(function() {
$('a').each(function(i) {
var html = $(this).html() + '';
html = html.replace(/View All Customer Reviews/g, '<span class="redbutton">View All Reviews »</span>');
$(this).html(html);
});
});
</script>
答案 1 :(得分:0)