简体   繁体   English

如何在不使用remove方法的情况下使用jquery删除span标签?

[英]How to remove span tag using jquery without using remove method?

can you please tell me how to remove the span tag using jquery. 您能告诉我如何使用jquery删除span标签吗? INPUT 输入

<span class="abc">PQR </span>

OUTPUT 输出值

PQR

I done before but don't remember I think I used regex or replace .:( 我之前做过,但不记得我认为我使用了正则表达式或替换。:(

Second 第二

How to replace &nbsp by a space(" ") ? 如何用空格(“”)替换&nbsp?

I used like that but not work. 我曾经那样,但没有用。

replace(/&nbsp;/g,'');

For the first part, Tim's answer is great. 在第一部分中,蒂姆的答案很棒。 $('.abd').contents().unwrap() . $('.abd').contents().unwrap()

For the second part, please do it properly. 对于第二部分, 正确执行。 &nbsp; is an html-encoded special characters (non-breakable space), but there are tons of other characters you can encounter (like &eacute; for é ). 是html编码的特殊字符(不可中断的空格),但是您可以遇到很多其他字符(例如&eacute; é )。

Unfortunately there's no built-in standard html decode function, but you can create one with jquery like this: 不幸的是,没有内置的标准html解码功能,但是您可以使用jquery创建这样的功能:

function htmlDecode(encodedText) {
  return $("<div>").html(encodedText).text();
}

For the first part, you can use $('.abc').contents().unwrap() 对于第一部分,您可以使用$('.abc').contents().unwrap()

For the second part see jods answer :) 对于第二部分,请参见jods答案:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM