简体   繁体   English

:包含IE8上的问题

[英]:contains issue on IE8

It seems that jQuery :contains selector does not work on IE8. 似乎jQuery :contains选择器在IE8上不起作用。

Please see following example on IE - LIVE DEMO 请参阅IE上的以下示例 - 现场演示

JS: JS:

$('table tr td:contains(" + ")').each( function(){
        $(this).addClass('url');
});

You need to convert the spaces in your TDs to HTML entities (   ) 您需要将TD中的空格转换为HTML实体(  

for $('table tr td:contains(" + ")') to work. for $('table tr td:contains(" + ")')工作。 (Same JS/CSS) (相同的JS / CSS)

HTML: HTML:

<table>
    <tr>
         <td>&nbsp;+&nbsp;</td>
         <td> 1 </td>
         <td> 3 </td>
         <td> 6 </td>
         <td> 7 </td>
    </tr>
</table>

However it will fail on modern browsers, so the solution is to replace the entities for those browsers. 但是它会在现代浏览器上失败,因此解决方案是替换这些浏览器的实体。 Just prepend this snippet before yours, it will do the job. 只需将此代码段添加到您的代码之前,它就能完成这项工作。

if( !($.browser.msie && $.browser.version < 10) ){
    $('table tr td').each(function(){
        $(this).html( $(this).html().replace(/&nbsp;/gi, ' ') );
    });
}

Another simpler solution to the IE8 :contains issue: IE8 :contains另一个更简单的解决方案IE8 :contains问题:

Make sure you are not using the space inside the string, eg 确保您没有使用字符串中的空格 ,例如

$('table tr td:contains("+")') will work even if your html have spaces <td> + </td> $('table tr td:contains("+")') 会工作 ,即使你的HTML有空格<td> + </td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM