不能用jQuery选择器在IE8中选择HTML5元素的子项 [英] Can't select HTML5 element's children in IE8 with jQuery selector
问题描述
我发现一些类似问题的帖子,但这是不同的。在我阅读另一篇文章后,我从jQuery 1.4升级到1.4.2,但问题依然存在。我也尝试运行IE 8兼容模式,没有什么似乎工作。当然,它在Chrome中的效果非常好。
I found some posts with similar issues, but this is something different. I upgraded from jQuery 1.4 to 1.4.2 after I read another post, but the problem still presents itself. I also tried running IE 8 in compatibility mode and nothing seemed to work. Of course, it works perfectly well in 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选择器
Here's the only jQuery selector that does work in this scenario...
$('.pleaseWaitButton').length // 1
这里的jQuery选择器将无法正常工作!
And here's the jQuery selectors that will not work!
$('.pleaseWaitButton').find('input').length // 0
$('.pleaseWaitButton input').length // 0
$('.pleaseWaitButton > p > input').length // 0
任何想法?任何人...?
Any ideas? Anyone...?
推荐答案
Internet Explorer 8对HTML 5,IE6和IE7的古怪支持只是不支持
Internet Explorer 8 has quirky support for HTML 5, IE6 and IE7 plain just don't support it.
您需要 shiv HTML 5元素,以便风格和正确使用方法/属性,如innerHTML,getElementsByTagName。
You need to shiv the HTML 5 elements in order to style and properly use methods/properties such as innerHTML, getElementsByTagName on them.
这将在IE6-IE8中工作:
This will work in 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
这篇关于不能用jQuery选择器在IE8中选择HTML5元素的子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!