当点击不同的图像时候显示对应的层,如何做for循环不用写太多的if语句
时间:2009-04-01
来源:互联网
各位大大,当点击不同的图像时候显示对应的层,如何做for循环不用写太多的if语句,谢谢!
sample:
<ul>
<li><img src="images/1.gif" width="60" height="60" border="0" style="cursor:pointer" id="1"/></li>
<li><img src="images/2.gif" width="60" height="60" border="0" style="cursor:pointer" id="2"/></li>
<li><img src="images/3.gif" width="60" height="60" border="0" style="cursor:pointer" id="3"/></li>
<li><img src="images/4.gif" width="60" height="60" border="0" style="cursor:pointer" id="4"/></li>
<li><img src="images/5.gif" width="60" height="60" border="0" style="cursor:pointer" id="5"/></li>
<li><img src="images/6.gif" width="60" height="60" border="0" style="cursor:pointer"/></li>
<li><img src="images/7.gif" width="60" height="60" border="0" style="cursor:pointer"/></li>
<li><img src="images/8.gif" width="60" height="60" border="0" style="cursor:pointer"/></li>
<li><img src="images/9.gif" width="60" height="60" border="0" style="cursor:pointer"/></li>
</ul>
<script language="javascript">
$(document).ready(function(){
$("img").click(function(){
if (this.id == "1"){
$(".STYLE2").hide()
$("#28").show();
}
else if (this.id=="2"){
$(".STYLE2").hide()
$("#29").show();
}
else if (this.id=="3"){
$(".STYLE2").hide()
$("#30").show();
}
else if (this.id=="4"){
$(".STYLE2").hide()
$("#31").show();
}
})
sample:
<ul>
<li><img src="images/1.gif" width="60" height="60" border="0" style="cursor:pointer" id="1"/></li>
<li><img src="images/2.gif" width="60" height="60" border="0" style="cursor:pointer" id="2"/></li>
<li><img src="images/3.gif" width="60" height="60" border="0" style="cursor:pointer" id="3"/></li>
<li><img src="images/4.gif" width="60" height="60" border="0" style="cursor:pointer" id="4"/></li>
<li><img src="images/5.gif" width="60" height="60" border="0" style="cursor:pointer" id="5"/></li>
<li><img src="images/6.gif" width="60" height="60" border="0" style="cursor:pointer"/></li>
<li><img src="images/7.gif" width="60" height="60" border="0" style="cursor:pointer"/></li>
<li><img src="images/8.gif" width="60" height="60" border="0" style="cursor:pointer"/></li>
<li><img src="images/9.gif" width="60" height="60" border="0" style="cursor:pointer"/></li>
</ul>
<script language="javascript">
$(document).ready(function(){
$("img").click(function(){
if (this.id == "1"){
$(".STYLE2").hide()
$("#28").show();
}
else if (this.id=="2"){
$(".STYLE2").hide()
$("#29").show();
}
else if (this.id=="3"){
$(".STYLE2").hide()
$("#30").show();
}
else if (this.id=="4"){
$(".STYLE2").hide()
$("#31").show();
}
})
作者: jacky_huang 发布时间: 2009-04-01
为什么不把层的ID有序话类?比如说DIV+当前ID组成一个新的层.这样就好实现了.
$('img').each(function(i){
$(this).eq(i).click(function(){
$('.style2').hide();
$('div'+i).show()
})
}
)
以上代码是我一时想出来的.不知道对不对.希望对你有帮助
$('img').each(function(i){
$(this).eq(i).click(function(){
$('.style2').hide();
$('div'+i).show()
})
}
)
以上代码是我一时想出来的.不知道对不对.希望对你有帮助
作者: huboqiao 发布时间: 2009-04-02
复制代码
|
作者: conjees 发布时间: 2009-04-13
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28