码迷,mamicode.com
首页 > 编程语言 > 详细

字符串转数组

时间:2017-06-08 11:58:21      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:btn   dsl   gallery   func   htm   des   new   enter   wrap   

将字符串按某个字符切割成若干个字符串,并以数组形式返回

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;
}

 

字符串转数组

标签:btn   dsl   gallery   func   htm   des   new   enter   wrap   

原文地址:http://www.cnblogs.com/wang715100018066/p/6961941.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!