抓取text()时如何去除空格 [英] How do I strip white space when grabbing a text()

查看:105
本文介绍了抓取text()时如何去除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下jquery语句.我希望删除空白,如下所示.所以,如果我有这样的字眼:

I have the following jquery statement. I wish to remove the whitespace as shown below. So if I have a word like:

例如
"#wordOperatingSystem/test "我希望最终结果显示" #wordOperatingSystemtest ". (即没有斜线和空格).斜线工作正常,但我无法删除空间.请帮忙!

For example
"#wordOperating System/test" I would like the end result to show me "#wordOperatingSystemtest". (ie without slash and space). The slash works fine but I can't get the space to be removed. Please help!

$("#word" + lbl.eq(i).text().replace("/","\\/").replace(/ /,'')).hide();

推荐答案

尝试全局修饰符:

.replace(/ /g, '')

同样的用于替换斜杠(如果字符串中有多个/):

Same goes for your slash replacement (in case there are multiple /s in your string):

.replace(/\//g, '\\/')

这篇关于抓取text()时如何去除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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