将字符串按某个字符切割成若干个字符串,并以数组形式返回
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 = "<div class='swiper-wrapper'>"; for(var i in dataLargeSrc){ topHtml+= "<div class='swiper-slide' style='background-image:url("+dataLargeSrc[i]+")'></div>"; } topHtml += "</div>"; $(".gallery-top").append(topHtml); var btn = "<div class='swiper-button-next swiper-button-white'></div><div class='swiper-button-prev swiper-button-white'></div>"; $(".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 = "<div class='swiper-wrapper'>"; for(var i in data360Src){ thumbsHtml+= "<div class='swiper-slide' style='background-image:url("+data360Src[i]+")'></div>"; } thumbsHtml += "</div>"; $(".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; }
只有在泥泞的道路上才能留下脚印
今天的文章字符串转数组分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/55481.html