我有以下范围
<span class="base" data-ui-id="page-title-wrapper">Search results for: 'soda'</span>
我想删除Search results for
并替换为其他文字
这是jquery
$(".base span").text(function(index, text) {
return text.replace('Search results for', 'We got you');
});
这是jsfiddle https://jsfiddle.net/kcLuh0a1/1/
为什么代码不会改变文本?
答案 0 :(得分:0)
您的问题是找不到.base span
。请改用span.base
。
$("span.base").text(function(index, text) {
return text.replace('Search results for', 'We got you');
});
JSFiddle:https://jsfiddle.net/y3a98pde/
答案 1 :(得分:0)
根据您的代码,您在元素span
base
元素
但是你需要将它应用于span,所以你的代码就像这样
$("span.base").text(function(index, text) {
return text.replace('Search results for', 'We got you');
});