JavaScript   发布时间:2022-04-16  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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

大佬总结

以上是大佬教程为你收集整理的javascript – 无法使用jQuery选择器在IE8中选择HTML5元素的子项全部内容,希望文章能够帮你解决javascript – 无法使用jQuery选择器在IE8中选择HTML5元素的子项所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。