0
<div>
<span>
          <span style="font-weight: bold;">MyName</span>
</span>
</div>

MyName の前後のスパンを削除し、最初のスパンを残すにはどうすればよいですか?

ありがとう

4

3 に答える 3

1

.contents()と組み合わせて.unwrap()を使用します。

$('#innerspan').contents().unwrap();​

マークアップ:

<span>
  <span id="innerspan" style="font-weight: bold;">MyName</span>
</span>​​​​​​​​​​​​​​​​​​​​​​​​​​

ライブデモ

于 2012-07-20T11:15:18.683 に答える
0

You can do next this time:

$('span').each(function() {  
   if ($(this).html() == "MyName") {
   $(this).parent().html("MyName");
  }
});

But it's very localized code.

于 2012-07-20T12:16:13.867 に答える
0

文字列を要素に変換し、スパンのHTMLコンテンツを取得します。

s = $(s).html();
于 2012-07-20T11:22:30.060 に答える