无法使用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屋!