Javascript 如何使用JS/jQuery在IE中捕获注释节点类型8?

Javascript 如何使用JS/jQuery在IE中捕获注释节点类型8?,javascript,jquery,Javascript,Jquery,我试图捕捉一个特定的评论行。以下代码适用于除IE之外的所有浏览器: <script> var llf = jQuery('.select').contents().filter(function() { return this.nodeType === 8 // Comment node })[2].nodeValue.replace("LLF: ", "").trim(); console.log(llf); alert(llf); </script> var ll

我试图捕捉一个特定的评论行。以下代码适用于除IE之外的所有浏览器:

<script>
var llf = jQuery('.select').contents().filter(function() {
return this.nodeType === 8 // Comment node
})[2].nodeValue.replace("LLF: ", "").trim();
console.log(llf);
alert(llf);
</script>

var llf=jQuery('.select').contents().filter(函数(){
返回this.nodeType==8//注释节点
})[2] .nodeValue.replace(“LLF:,”).trim();
控制台日志(llf);
警报(llf);
这是HTML:

<td class="select" nowrap="nowrap" rowspan="3">
<!-- NON IDEAL REASON:  1 hour time window -->
<b>$423.59</b><br />
<b>&#163;267.50</b><br />
<!--  Policy Name: Investment Bank -->
<!--LLF: 1253.12 --> //This is the line I want to capture

423.59美元
£267.50
//这就是我想要捕捉的线
如果有一种方法可以适用于所有浏览器,那就太好了,但是如果你能想出一种针对IE+的特定解决方案,条件注释也可以

谢谢

IE没有,这是最近在ES5中才引入的,所以当您尝试使用它时,它会抛出一个异常。但在使用jQuery时,可以使用
jQuery.trim

var llf = jQuery.trim(jQuery('.select').contents().filter(function() {
    return this.nodeType === 8; // Comment node
})[2].nodeValue.replace("LLF: ", ""));
console.log(llf);
alert(llf);
|-在IE7和IE9中对我有效,所以我也认为是IE8


我建议将该语句分解一下(尤其是这样的问题更容易调试),并在IE没有的
==8

后面加上分号,这是最近在ES5中才引入的,因此在尝试使用它时会抛出异常。但在使用jQuery时,可以使用
jQuery.trim

var llf = jQuery.trim(jQuery('.select').contents().filter(function() {
    return this.nodeType === 8; // Comment node
})[2].nodeValue.replace("LLF: ", ""));
console.log(llf);
alert(llf);
|-在IE7和IE9中对我有效,所以我也认为是IE8



我建议将该语句分解一下(尤其是这样的问题更容易调试),并在
==8

@fedxc:LOL,不用担心,很高兴它有帮助。@fedxc:LOL,不用担心,很高兴它有帮助。