簡體   English   中英

如何使用JavaScript捕獲帶注釋的HTML?

[英]How to capture commented HTML with JavaScript?

我想知道是否可以使用JavaScript捕獲注釋的注釋。

這句話在soruce代碼上看起來像這樣:

<div id='ContainerId'>
<!-- NON IDEAL REASON: 90 min time window depart arrive -->
<b>1,107.45 GBP</b><br />
<!--LLF: 1107.45 -->
</div>

我需要在變量中保存該值(在本例中為1107.45)。

這似乎不起作用:

var LLF = jQuery("contains('LLF')");

有任何想法嗎?

謝謝!

$('#ContainerId').contents().filter(function(){
    return this.nodeType === 8 // Comment node
});

現場演示

和完整的代碼:

var comment = $('#ContainerId').contents().filter(function() {
    return this.nodeType === 8 // Comment node
})[0].nodeValue;

console.log(comment.match(/\d+\.\d+/g));​​​​​

現場演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM