查询;显示/隐藏在 IE 中不会触发,可在其他浏览器上运行
好的,下面是我用于该网站的代码的一部分。它应该是您单击图像的位置,它“显示”之前隐藏的 div。然后,当您单击另一张图片时,它会隐藏当前打开的 div 并显示新的 div。它适用于除 IE 之外的所有浏览器(当然)。我不确定我的脚本做错了什么,请帮忙?
<div class="content">
<table width="100%" border="0">
<tr>
<td align="center">
<a id="1" href="#"><img src="..." width="100" height="92" alt="1" /></a>
<a id="2" href="#"><img src="..." width="100" height="70" alt="2" /></a>
<a id="3" href="#"><img src="..." width="100" height="112" alt="3" /></a>
<a id="4" href="#"><img src="..." width="100" height="65" alt="4" /></a>
<a id="5" href="#"><img src="..." width="100" height="141" alt="5" /></a>
</td>
</tr>
</table>
</div>
<div id="frame1">
<button>close</button>
<iframe src="..." width="100%" height="100%">
<p>Your browser does not support iframes.</p>
</iframe>
</div>
<div id="frame2">
<button>close</button>
<iframe src="..." width="100%" height="100%">
<p>Your browser does not support iframes.</p>
</iframe>
</div>
<div id="frame3">
<button>close</button>
<iframe src="..." width="100%" height="100%">
<p>Your browser does not support iframes.</p>
</iframe>
</div>
等等...
<script>
//controller for first site
$("a#1").click(function () {
$("#frame2,#frame3,#frame4,#frame5").hide("fast");
$("#frame1").show("slow");
});
//controller for second site
$("a#2").click(function () {
$("#frame1,#frame3,#frame4,#frame5").hide("fast");
$("#frame2").show("slow");
});
//controller for third site
$("a#3").click(function () {
$("#frame1,#frame2,#frame4,#frame5").hide("fast");
$("#frame3").show("slow");
});
//controller for fourth site
$("a#4").click(function () {
$("#frame1,#frame2,#frame3,#frame5").hide("fast");
$("#frame4").show("slow");
});
//controller for fifth site
$("a#5").click(function () {
$("#frame1,#frame2,#frame3,#frame4").hide("fast");
$("#frame5").show("slow");
});
//button close frames
$("button").click(function () {
$("#frame1,#frame2,#frame3,#frame4,#frame5").hide("fast");
});
</script>
当然,框架 div 的 css 必须是“display:none;”让它发挥作用。
okay below is part of the code im using for this site. its supposed to be where you click on the image and it "shows" a div that was hidden before. Then when you click another picture it hides the currently opened div and shows the new one. it works in every browser except IE (of course.) and im not sure what i did wrong with script, help please?
<div class="content">
<table width="100%" border="0">
<tr>
<td align="center">
<a id="1" href="#"><img src="..." width="100" height="92" alt="1" /></a>
<a id="2" href="#"><img src="..." width="100" height="70" alt="2" /></a>
<a id="3" href="#"><img src="..." width="100" height="112" alt="3" /></a>
<a id="4" href="#"><img src="..." width="100" height="65" alt="4" /></a>
<a id="5" href="#"><img src="..." width="100" height="141" alt="5" /></a>
</td>
</tr>
</table>
</div>
<div id="frame1">
<button>close</button>
<iframe src="..." width="100%" height="100%">
<p>Your browser does not support iframes.</p>
</iframe>
</div>
<div id="frame2">
<button>close</button>
<iframe src="..." width="100%" height="100%">
<p>Your browser does not support iframes.</p>
</iframe>
</div>
<div id="frame3">
<button>close</button>
<iframe src="..." width="100%" height="100%">
<p>Your browser does not support iframes.</p>
</iframe>
</div>
etc...
<script>
//controller for first site
$("a#1").click(function () {
$("#frame2,#frame3,#frame4,#frame5").hide("fast");
$("#frame1").show("slow");
});
//controller for second site
$("a#2").click(function () {
$("#frame1,#frame3,#frame4,#frame5").hide("fast");
$("#frame2").show("slow");
});
//controller for third site
$("a#3").click(function () {
$("#frame1,#frame2,#frame4,#frame5").hide("fast");
$("#frame3").show("slow");
});
//controller for fourth site
$("a#4").click(function () {
$("#frame1,#frame2,#frame3,#frame5").hide("fast");
$("#frame4").show("slow");
});
//controller for fifth site
$("a#5").click(function () {
$("#frame1,#frame2,#frame3,#frame4").hide("fast");
$("#frame5").show("slow");
});
//button close frames
$("button").click(function () {
$("#frame1,#frame2,#frame3,#frame4,#frame5").hide("fast");
});
</script>
and of course the css of the frame divs had to be "display:none;" for it to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
注意:你的做法不是一个好的做法。
Note: Your is not a good practice.
我记得有类似的问题...隐藏所有然后显示一个为我解决了问题...
所以尝试一下
并尝试使用其他标识符然后枚举
I remember having similar problem... Hiding ALL and then showing one fixed the problem for me...
so just give a try with
and try to use other identifier then enumeration
只需尝试以下代码,但不确定,
Just give a try with following code, but not sure,
您是否已将 jQuery 代码放入 文档就绪块 中?
有点像这样:
当 Firefox 能够在执行之前加载我的 javascript 文件时,我也遇到了这个问题。 IE 在这方面遇到了更多问题。
编辑:尝试为链接使用文本 ID。
例如:
ID 不应该以数字开头,因此 IE 可能会出现问题。
Have you put your jQuery code in a document ready block?
Kind of like so:
I had that problem aswell when Firefox was able to load my javascript files before executing. IE had a bit more problems with that.
Edit: try using a textual ID for your links.
e.g:
ID's aren't meant to start with numbers, so IE could give problems on this.
我认为您应该尝试提供不以数字开头的链接 ID 值。 数字对于 ID 和 NAME 属性无效,但它们可以用在初始字符之后。
另外,我可以建议你写出类似这样的代码:
这样,你只有这一小块代码来处理处理
IFRAME
显示/隐藏行为的所有重复代码。只要你愿意就可以调整它。I think you should try giving your links ID values that don't start with numbers. Numbers aren't valid to start out ID and NAME attributes, but they can be used after the initial character.
Also, may I suggest that you write out your code something like:
This way, you only have this small chunk of code that takes care of all that repeated code that handles the
IFRAME
show/hide behavior. Just tweak it as you would please.