如何使用 JQuery 删除文本括号?
我有一些自动生成的文本,其中包含非 ASCII 编码的括号。例如:
<div> Some text (these are the non-ascii encoded parenthesis).
<div>
我想去掉括号。我有以下内容,我在其他地方使用它来清理一些 html 元素,但我无法获得类似于删除实际文本的工作:
jQuery(document).ready(function(){jQuery(".block").find("p").remove()});
我发现了一些想法,但它们处理普通文本。摆脱括号是一个挑战,因为我不确定如何编写括号以便 jQuery 理解它。
有什么想法吗?
I have some auto-generated text that includes non-ascii encoded parentheses. For example:
<div> Some text (these are the non-ascii encoded parenthesis).
<div>
I want to get rid of the parenthesis. I have the following, which I use elsewhere to clean out some html elements, but I can't get similar to work to remove actual text:
jQuery(document).ready(function(){jQuery(".block").find("p").remove()});
I've found a few ideas around, but they deal with normal text. Getting rid of a parenthesis is a challenge, as I'm not sure how to code the parenthesis so that jQuery understands it.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用普通 Javascript 进行替换/清理。类似的事情
就会做到。请注意,这将查询整侧的所有
节点,您希望对选择器更加具体。
演示: http://jsfiddle.net/2gHh2/
如果您想删除括号和中间的所有内容,您可以只需将正则表达式更改为
/\(.*?\)/g
即可。You should do the replacing/cleaning with vanilla Javascript. Something like
will do it. Notice, this would query for all
<div>
nodes on the entire side, you want to be more specific on the selector.demo: http://jsfiddle.net/2gHh2/
If you'd like to remove the parenthesis and everything in between, you'd simply have to change the regular expression to
/\(.*?\)/g
.