js点击左右按钮来切换多张图片

var _thtml="";
var imgs=data.img.split(",");
_thtml+="<img id='t1' class='imgs' src='"+imgs[0]+"' style='width: 80%;height: 75%;display: block'>";
	if(imgs.length>1){
    
    
	//将图片数组数据存到隐藏input value里
	 $("#tr_img_value").val(data.img)
_thtml+="<img id='tjt1' class='imgs' src='../images/bz_zjt.png' style='width: 8%;height: 						  5%;position: absolute;left: -10%;top: 35%;display: none;z-index:99999;'>";
_thtml+="<img id='tjt2' class='imgs' src='../images/bz_yjt.png' style='width: 8%;height: 5%;position: absolute;left: 82%;top: 35%;z-index:99999;'>";
     }
					$("#tr_img").html(_thtml)
					//获取保存的图片数组数据
                    var imgs3=$("#tr_img_value").val().split(",")
                    var j=0;
                    $("#tjt1").on("click",function () {
    
    
                        if(j>0){
    
    
                            j--;
                            if(j==0){
    
    
                                $("#t1").attr("src",imgs3[j])
                                $("#tjt1").hide();
                                $("#tjt2").show();
                            }else{
    
    
                                $("#tjt1").show();
                                $("#tjt2").show();
                                $("#t1").attr("src",imgs3[j])
                            }
                        }
                    })
                    $("#tjt2").on("click",function () {
    
    
                        j++;
                        if(j<=imgs3.length-1){
    
    
                            if(j==imgs3.length-1){
    
    
                                $("#t1").attr("src",imgs3[j])
                                $("#tjt1").show();
                                $("#tjt2").hide();
                            }else{
    
    
                                $("#tjt1").show();
                                $("#tjt2").show();
                                $("#t1").attr("src",imgs3[j])
                            }
                        }
                    })

猜你喜欢

转载自blog.csdn.net/qq_40136782/article/details/111869894
今日推荐