jquery替换不起作用 [英] jquery replace is not working

查看:85
本文介绍了jquery替换不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DEMO

您好我在尝试从JS中删除箭头。但似乎替换不起作用:-(

Hi Am trying to remove the arrows from JS. but seems like replace is not working :-(

<a class="pr-page-prev">« Previous</a>
<a class="pr-page-next">Next »</a>


$('.pr-page-prev').text().replace(/&laquo;/, '')
$('.pr-page-next').text().replace(/&raquo;/, '')


推荐答案

您正在替换文本而不是内容元素。

You are replacing the text but not the content of the element.

当你说 $('。pr-page-prev')。text()时,它返回你正在调用replace的文本内容,它将返回被替换的文本,但它不会被设置回元素。所以即使你已经替换了文本,它也不会被应用到元素。

When you say $('.pr-page-prev').text(), it returns the text content on which you are calling replace which will return the replaced text but it is not set back to the element. So even if you have replaced the text it won't be applied to the element.

$('.pr-page-prev').text(function(i, text){return text.replace(/«/, '')})
$('.pr-page-next').text(function(i, text){return text.replace(/»/, '')})

演示:小提琴

这篇关于jquery替换不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆