使用与 jQuery.html() 链接的 jQuery.not()
是否可以使用与 jQuery.html()
链接的 jQuery.not()
?
winner.not('a').html()
其中 winner
是一个 jQuery 对象/包装集,我试图返回删除锚点的 HTML。
Is it possible to use jQuery.not()
chained with jQuery.html()
?
winner.not('a').html()
Where winner
is a jQuery object/wrapped set, I am trying to return HTML with anchors removed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.html()
将返回innerHTML - 其中将包含任何 A 标签,您可以这样做:另外 - 如果您想获取 A 中的文本- 但不是 A 本身 - 你可以使用:
虽然如果
中有任何其他标签,这实际上可能会有点混乱 - 它应该说明这个想法。
.html()
is going to return the innerHTML - which will include any A tags inside, you may be able to do something like this though:Also - If you wanted to get the text within the A still - but not the A itself - you could use:
Although that might actually get a little messy if the
<a>
has any other tags within it - it should illustrate the idea.这是可能的,但不会给您带来预期的结果。
not('a')
将从您的winner
集合中过滤a
标签,但html()
会返回您集合中第一项的值。因此,如果您的
获胜者
有[div#i1 div#i2 a div#i3 a]
,not('a')
将减少此组[div#i1 div#i2 div#i3]
和html()
将返回div#i1
的 HTML 内容。如果你想从 HTML 中删除锚点,我认为你应该首先使用
.html()
方法,然后用一些正则表达式替换返回的值,以去除锚点。It is possible but that won't give you the result you expect.
not('a')
will filtera
tags from yourwinner
collection buthtml()
will return you the value of the first item in the collection.so if your
winner
has[div#i1 div#i2 a div#i3 a]
,not('a')
will reduce this set to[div#i1 div#i2 div#i3]
andhtml()
will return HTML contents ofdiv#i1
.If you want to remove anchors from HTML I think you should first get is using
.html()
method and then do a replace on the value returned with some regular expression that will strip the anchors.或者,您可以使用类似这样的方法:
获取非 a 元素的 html 的串联。然而,这可能会错过各种标签封闭项目之间的任何顶级文本。
Alternatively, you could use something like this:
to get the concatenation of the non-a elements' html. However, this may miss any top-level text in between the various tag-enclosed items.