jQuery hide() 不起作用 (IE9)
我正在制作一个 div,它应该在页面加载时隐藏,然后在用户单击链接后可见。下面的代码适用于 FF / IE7 / IE8,但不适用于 IE9,其中 div 始终可见(无内容)。提前致谢!
<script>
$(document).ready(function() {
$('#translateBoxen').hide();
$('#translateToggle').click(function() {
$('#translateBoxen').toggle(400);
return false;
});
});
</script> // This is the jQuery code to hide and toggle the div //
<div style="width:200px;height:100px;position:absolute;"> // Just a holder that's needed for the site
<a class="vitxtext" style="font-size:10px;" id="translateToggle" href="#">
Translate
</a>
<div style="clear:both;"></div>
<div id="translateBoxen">
// BOX CONTENT //
</div>
</div>
I am making a div which should be hidden when the page loads, then visible once the user clicks a link. The code below works in FF / IE7 / IE8 but not in IE9, where the div is visible at all times ( without content ). Thanks in advance!
<script>
$(document).ready(function() {
$('#translateBoxen').hide();
$('#translateToggle').click(function() {
$('#translateBoxen').toggle(400);
return false;
});
});
</script> // This is the jQuery code to hide and toggle the div //
<div style="width:200px;height:100px;position:absolute;"> // Just a holder that's needed for the site
<a class="vitxtext" style="font-size:10px;" id="translateToggle" href="#">
Translate
</a>
<div style="clear:both;"></div>
<div id="translateBoxen">
// BOX CONTENT //
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不用 CSS 隐藏
呢?只需在 CSS 中设置为
display:none
,然后当第一次单击切换链接时,应该会显示它。toggle()
没有理由不能在 IE9 中工作,您是否遇到任何脚本错误?Why don't you hide the
<div>
with CSS? Just set to todisplay:none
in your CSS, then when the toggle link is clicked for the first time it should be shown.There is no reason why
toggle()
should not work in IE9, are you getting any script errors?迟到了,但尝试使用
display:none
创建一个.hidden
类,然后通过放置addClass('hidden')
来隐藏/显示和removeClass('hidden')
而不是显示/隐藏。Late to the party, but try making a
.hidden
class withdisplay:none
, then hiding/showing by puttingaddClass('hidden')
andremoveClass('hidden')
instead of show/hide.