我有這個演示,並嘗試獲取div的文本。
獲取div的文本不跨度
<script>
var string = "<span>this is span</span>new line";
var anchors = $('<div/>').append(string).find('span').text();
console.log(anchors);
</script>
格看起來像
<div>
<span>this is span</span>
new line
</div>
輸出: -
this is span
,並希望new line