我正在尝试使用 jquery 将面包屑箭头 > ( >
) 更改为 »。
<div id="breadcrumbs">
<a title="Go to cbc." href="http://cbcsales.co.il/newsite" class="home">Home</a>
> testpage</div>
我尝试使用以下 jquery。但是标签不见了。它是替换 <a>
标签 >
特点。帮我。谢谢
jQuery("#breadcrumbs").text(function(index, text) {
return text.replace('>', '»');
});
最佳答案
只需在元素本身上调用 replace
,而不是在函数内:
演示
jQuery("#breadcrumbs").html(
jQuery("#breadcrumbs").html().replace('>', '»')
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="breadcrumbs">
<a title="Go to cbc." href="http://cbcsales.co.il/newsite" class="home">Home</a>
> testpage
</div>
关于jquery替换> html代码上的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27580792/