JS控制img图片显示与隐藏的问题,昐朋友相助
需要实现的功能是:后台有5个上传产品缩略图的选项,前台调用后台的是src="后台上传的路径"现在我需要做一个判断,当后台没有上传图片的时候就隐藏这个img标签<scrip...
需要实现的功能是:
后台有5个上传产品缩略图的选项,前台调用后台的是src="后台上传的路径"
现在我需要做一个判断,当后台没有上传图片的时候就隐藏这个img标签
<script type="text/javascript">
var litpic2 = document.getElementById("litpic2");
if(litpic2){
var pic2 = document.getElementById("litpic2").src;
var pic2_2 = location.href.substring(0,location.href.lastIndexOf('/')+1);
if(pic2 == null || pic2 == pic2_2){
document.getElementById("litpic2").style.display = "none";
}
}
var litpic3 = document.getElementById("litpic3");
if(litpic3){
var pic3 = document.getElementById("litpic3").src;
var pic3_3 = location.href.substring(0,location.href.lastIndexOf('/')+1);
if(pic3 == null || pic3 == pic3_3){
document.getElementById("litpic3").style.display = "none";
}
}
var litpic4 = document.getElementById("litpic4");
if(litpic4){
var pic4 = document.getElementById("litpic4").src;
var pic4_4 = location.href.substring(0,location.href.lastIndexOf('/')+1);
if(pic4 == null || pic4 == pic4_4){
document.getElementById("litpic4").style.display = "none";
}
}
var litpic5 = document.getElementById("litpic5");
if(litpic5){
var pic5 = document.getElementById("litpic5").src;
var pic5_5 = location.href.substring(0,location.href.lastIndexOf('/')+1);
if(pic5 == null || pic5 == pic5_5){
document.getElementById("litpic5").style.display = "none";
}
}
</script> 展开
后台有5个上传产品缩略图的选项,前台调用后台的是src="后台上传的路径"
现在我需要做一个判断,当后台没有上传图片的时候就隐藏这个img标签
<script type="text/javascript">
var litpic2 = document.getElementById("litpic2");
if(litpic2){
var pic2 = document.getElementById("litpic2").src;
var pic2_2 = location.href.substring(0,location.href.lastIndexOf('/')+1);
if(pic2 == null || pic2 == pic2_2){
document.getElementById("litpic2").style.display = "none";
}
}
var litpic3 = document.getElementById("litpic3");
if(litpic3){
var pic3 = document.getElementById("litpic3").src;
var pic3_3 = location.href.substring(0,location.href.lastIndexOf('/')+1);
if(pic3 == null || pic3 == pic3_3){
document.getElementById("litpic3").style.display = "none";
}
}
var litpic4 = document.getElementById("litpic4");
if(litpic4){
var pic4 = document.getElementById("litpic4").src;
var pic4_4 = location.href.substring(0,location.href.lastIndexOf('/')+1);
if(pic4 == null || pic4 == pic4_4){
document.getElementById("litpic4").style.display = "none";
}
}
var litpic5 = document.getElementById("litpic5");
if(litpic5){
var pic5 = document.getElementById("litpic5").src;
var pic5_5 = location.href.substring(0,location.href.lastIndexOf('/')+1);
if(pic5 == null || pic5 == pic5_5){
document.getElementById("litpic5").style.display = "none";
}
}
</script> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询