Php jquery不能与IE 8一起使用
我正在尝试用一个表行实现切换函数。除了IE8,一切都很顺利。下面给出了我使用的脚本Php jquery不能与IE 8一起使用,php,jquery,internet-explorer,Php,Jquery,Internet Explorer,我正在尝试用一个表行实现切换函数。除了IE8,一切都很顺利。下面给出了我使用的脚本 <script src="jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $("#report tr:odd").addClass("odd"); $("#repo
<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#report tr:odd").addClass("odd");
$("#report tr:not(.odd)").hide();
$("#report tr:first-child").show();
$("#report tr.odd").click(function(){
$(this).next("tr").each(function (){ this.toggle()});
$(this).find(".arrow").toggleClass("up");
});
//$("#report").jExpand();
});
</script>
$(文档).ready(函数(){
$(“#报告tr:odd”).addClass(“odd”);
$(“#报告tr:not(.odd)”).hide();
$(“#报告tr:第一个孩子”).show();
$(“#report tr.odd”)。单击(函数(){
$(this.next(“tr”).each(函数(){this.toggle()});
$(this.find(“.arrow”).toggleClass(“向上”);
});
//$(“#报告”).jExpand();
});
谁来帮帮我
Jessica您需要包装()您的this
(它只是该循环中的一个DOM元素,而不是jQuery对象)才能访问,如下所示:
$(this).toggle()
$("#report tr.odd").click(function(){
var show = $(this).find(".arrow").toggleClass("up").hasClass("up");
$(this).next("tr").toggle(show);
});
但这里不需要循环,这是:
$(this).next("tr").each(function (){ $(this).toggle()});
可能就是这样:
$(this).next("tr").toggle();
它将在所有找到的元素上运行…即使这里只有一个元素
问题2是IE8特别认为下一行总是可见的(这是您正在使用的jQuery 1.3.2实现中的一个bug)。这里有两个选项,快速修复方法是像这样重新编写:
$(this).toggle()
$("#report tr.odd").click(function(){
var show = $(this).find(".arrow").toggleClass("up").hasClass("up");
$(this).next("tr").toggle(show);
});
。或者对我来说更好的解决方案,升级到最新的jQuery(1.4.3),也可以在IE8中工作。在您的领域:
$(this).next("tr").each(function (){ this.toggle()});
尝试将其更改为:
$(this).next("tr").each(function (){ $(this).toggle()});
我以前在一些浏览器上遇到过这个问题,无法区分this和$(this)
因此,您将得到:
$(document).ready(function(){
$("#report tr:odd").addClass("odd");
$("#report tr:not(.odd)").hide();
$("#report tr:first-child").show();
$("#report tr.odd").click(function(){
$(this).next("tr").each(function (){ $(this).toggle()});
$(this).find(".arrow").toggleClass("up");
});
});
什么不起作用?您会遇到什么错误?当我单击该行时,切换功能(隐藏和显示内容)不起作用..我将其设置为$(this).next(“tr”).toggle();但是不工作(仅在IE 8中),有什么解决方案吗?请帮助我。非常感谢Nick Craver、Pekka和EMMERICH在这个问题上帮助我。。它现在可以工作了。这不是特定于浏览器的问题,这永远不会工作。哦,你说得对。我想当我遇到这个问题时,它可能有点不同。我把它做成了$(this).next(“tr”).toggle();但是不工作(仅在IE 8中),有什么解决方案吗?请帮帮我。我已经复制了你的代码,应用了我们讨论过的修复程序,它很有效。后来就是这样。但这也不行。@jessi-你有一个例子页吗?如果没有标记,我们无法说什么可以100%解决您的问题,但是我描述/演示的如何解决上述问题100%肯定会引发错误。是的,我从下面的URL@jessi获得了一个示例-问题是IE8中的高度检测,jQuery 1.3.2认为行已经可见,这在以后的版本中有所更改,您可以更改代码或更新jQuery…我已经在更新的asnwer中详细阐述了以上两个方面。非常感谢Nick Craver、Pekka、EMMERICH在这个问题上的帮助。。现在可以工作了。。