<div>
<span>
<span style="font-weight: bold;">MyName</span>
</span>
</div>
我將如何移除MyName周圍的跨度,但保留初始跨度?刪除字符串周圍的標籤
感謝
<div>
<span>
<span style="font-weight: bold;">MyName</span>
</span>
</div>
我將如何移除MyName周圍的跨度,但保留初始跨度?刪除字符串周圍的標籤
感謝
使用.unwrap()一起選擇中與.contents():
$('#innerspan').contents().unwrap();
標記:
<span>
<span id="innerspan" style="font-weight: bold;">MyName</span>
</span>
打開串入元素並獲得跨度的HTML內容:
s = $(s).html();
你可以做接下來的這段時間:
$('span').each(function() {
if ($(this).html() == "MyName") {
$(this).parent().html("MyName");
}
});
但它是非常本地化的代碼。
沒有一種方法來確定跨度,除非要刪除所有嵌套跨度,否則不是真的可能。你可以改變HTML嗎?例如給它一個類。 – Thomas 2012-07-20 11:13:04
你的出發點是什麼?點擊「我的名字」?頁面加載? – 2012-07-20 11:14:28
已更改代碼以顯示每行如何開始 – ngplayground 2012-07-20 12:55:04