使用jquery从字符串中去除span标签
我想在按 Enter 时获取 ap 标记的文本值
$.keynav.enterDown = function () {
var accom = $('#suggestions p.keynavon').html();
alert(accom);
}
这工作很好,但结果包含 和
标记,是无论如何,我可以从字符串中删除这些标签吗?
I am wanting to take the text value of a p tag when I press enter
$.keynav.enterDown = function () {
var accom = $('#suggestions p.keynavon').html();
alert(accom);
}
This is working great but the results contain <span>
and </span>
tags, is there anyway I can strip those tags from the string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想要文本(听起来像您想要的文本),请使用
.text()
而不是
.html()
,如下所示:如果您确实需要专门删除
标签,请克隆内容(以免影响原始内容)并通过
.replaceWith()
,如下所示:If you just want the text, which sounds like what you're after, use
.text()
instead of.html()
, like this:If you actually need to strip the
<span>
tags specifically, clone the content (as to not affect the original) and replace them with their inner content via.replaceWith()
, like this: