我試圖使用clone()
,我很接近,但我不能代替文字,它顯示兩個:如何在<br>之後設置文字樣式?
var td_clone = $('.ms-vb').clone();
$('span', td_clone).remove();
$('br', td_clone).remove();
var name = $.trim(td_clone.text());
$("td").append(name.toUpperCase());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td width="80%" style="padding-bottom: 3px" class="ms-vb">
<span class="ms-announcementtitle">
title is here
</span>
<br>
by hey
</td>
</tr>
</table>
結果:
title is here
by hey BY HEY
雖然我期待:
title is here
BY HEY
爲什麼你克隆的元素,當你似乎想要改變他們到位? – adeneo
這是我發現在'
'之後發現文字的方式,如果你知道任何更好/更快的方法,請在答案上點燃 –
無論如何,你做了一個克隆。您刪除跨度和跨度內的文本。然後刪除中斷,剩下的就是包含'by hey'的textNode。你把這個字符串,大寫,並將其附加到你已經有的HTML? – adeneo