jQuery 和 IE 8 以及切换器仅打开第一个子项
我有一组像这样的 div,其中我可以有 x 个编号,如页面上下面的 div。
这是 div 代码
<div class="demo1">
<h3 class="expand2">1:00 pm – 4:00pm<br>Item 1<p></p>
<p><strong>Presented by:</strong><em><br></em></p></h3>
<div class="collapse" style="display: none; ">
<table border="0" cellpadding="0" cellspacing="0" width="600" align="center">
<tbody><tr>
<td align="left" valign="top">
<div id="speakerBlockArea">
<div id="leftcolumnSpeakerBlock"><span id="sessTitle">run by:</span></div>
<div id="rightcolumnSpeakerBlock">
</div>
</div>
</td>
</tr>
</tbody></table>
</div>
</div>
这是 JQuery
$(document).ready(function() {
$(".collapse").slideUp();
$("H3.expand2").click(function() {
//$(this).next(".collapse:first").slideToggle("slow");
$(".collapse").toggle($('.collapse').css('display') == 'none');
});
});
我终于让一切都可以与 IE 8 和其他浏览器一起使用,但现在我遇到一个问题,当我单击其中一个时,每个 div 都会展开。我怎样才能让它工作,以便在单击父项时只有子项展开。这样它就可以在 IE 8/9 中工作
现在代码的测试链接是 http://www.lvtravelshow.com/?page_id=2028
我已经有一个版本在 Chrome / Firefox 等中工作的代码。但是 IE 遇到了问题,所以我最终得到了上面的代码。
提前致谢。
I have a group of divs like such where I could have x number like the divs below on the page.
Here is the div code
<div class="demo1">
<h3 class="expand2">1:00 pm – 4:00pm<br>Item 1<p></p>
<p><strong>Presented by:</strong><em><br></em></p></h3>
<div class="collapse" style="display: none; ">
<table border="0" cellpadding="0" cellspacing="0" width="600" align="center">
<tbody><tr>
<td align="left" valign="top">
<div id="speakerBlockArea">
<div id="leftcolumnSpeakerBlock"><span id="sessTitle">run by:</span></div>
<div id="rightcolumnSpeakerBlock">
</div>
</div>
</td>
</tr>
</tbody></table>
</div>
</div>
This is the JQuery
$(document).ready(function() {
$(".collapse").slideUp();
$("H3.expand2").click(function() {
//$(this).next(".collapse:first").slideToggle("slow");
$(".collapse").toggle($('.collapse').css('display') == 'none');
});
});
I finally got everything working with IE 8 and the rest of the browsers but now I have a problem where every div expands when I click on just one of them. How can I get it to work so that only the child expands when parent is clicked. And so that it works in IE 8/9
The test link with the code as it stands now is
http://www.lvtravelshow.com/?page_id=2028
I have already a version of code that works in Chrome / Firefox etc. But IE is having the issue so I ended up with the above code.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的意思是这样吗?
$(this).parent('div').find('.collapse').toggle(); <---
这一行是找出被点击父级的 .collapse div,并切换它
Do you mean sth like this?
$(this).parent('div').find('.collapse').toggle(); <---
this line is to find out the .collapse div of the clicked parent, and toggle it