将字符串按某个字符切割成若干个字符串,并以数组形式返回
var s = "abc,abcd,aaa";ss = s.split(","); // 在每个逗号(,)处进行分解。console.log(ss); // ["abc", "abcd", "aaa"]
截取数组中_720替换为_360:
function changeLargeImg(self) { imgClear(); $("section").show(); // 大图 var dataLargeSrc = $(self).attr("data-largesrc"); dataLargeSrc = dataLargeSrc.split(","); var topHtml = ""; for(var i in dataLargeSrc){ topHtml+= " "; } topHtml += ""; $(".gallery-top").append(topHtml); var btn = " "; $(".gallery-top").append(btn); // 克隆,小图 var dataSrc = dataLargeSrc.slice(); var data360Src = []; for (var i in dataSrc) { data360Src.push(dataSrc[i].replace(/_720/, "_360")); //replace找到并替换,并返回新的数组,push放入新的数组中; } var thumbsHtml = ""; for(var i in data360Src){ thumbsHtml+= " "; } thumbsHtml += ""; $(".gallery-thumbs").append(thumbsHtml); // swiper图片动效启动 var galleryTop = new Swiper('.gallery-top', { nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', spaceBetween: 10 }); var galleryThumbs = new Swiper('.gallery-thumbs', { spaceBetween: 10, centeredSlides: true, slidesPerView: 'auto', touchRatio: 0.2, slideToClickedSlide: true }); // 双向控制 galleryTop.params.control = galleryThumbs; galleryThumbs.params.control = galleryTop;}