我发现一些帖子有类似的问题,但这是不同的。在阅读另一篇文章后,我从 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>
关于javascript - 无法使用 jQuery 选择器在 IE8 中选择 HTML5 元素的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3352538/