javascript – 无法使用jQuery选择器在IE8中选择HTML5元素的子项

我发现一些类似问题的帖子,但这是不同的.在我阅读另一篇文章后,我从jQuery 1.4升级到1.4.2,但问题依然存在.我也尝试运行IE 8兼容模式,没有什么似乎工作.当然,它在Chrome中效果非常好.

这是标记

<section class="pleaseWaitButton">
    <p><img src="images/please_wait.png" alt="Please wait" /></p>
    <p><input type="image" src="images/add_to_cart.png" alt="Add to cart"/></p>
</section>

这是在这种情况下唯一可以工作的jQuery选择器

$('.pleaseWaitButton').length // 1

这里的jQuery选择器将无法正常工作!

$('.pleaseWaitButton').find('input').length // 0
$('.pleaseWaitButton input').length // 0
$('.pleaseWaitButton > p > input').length // 0

有任何想法吗?任何人…?

解决方法

Internet Explorer 8对HTML 5,IE6和IE7平台的古怪支持只是不支持它.

您需要使用shiv的HTML 5元素,以便对其进行风格和正确使用方法/属性,如innerHTML,getElementsByTagName.

这将在IE6-IE8中工作:

<!doctype html> 
<html> 
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]--> 
<section class="pleaseWaitButton"> 
    <p><img src="images/please_wait.png" alt="Please wait" /></p> 
        <p><input type="image" src="images/add_to_cart.png" alt="Add to cart"/></p> 
</section> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script> 
<script> 
    alert( $('.pleaseWaitButton').find('input').length ) 
    alert( $('.pleaseWaitButton input').length ) 
    alert( $('.pleaseWaitButton > p > input').length ) 
</script> 
</html>

现场演示:http://medero.org/html5.html

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...