美文网首页
面试测试

面试测试

作者: 安石0 | 来源:发表于2017-08-27 23:52 被阅读0次

    获取左边的值

    var a=$('ul.JS_navCtn').find('a')//选择class等于JS_navCtn的ul节点的后代节点为a标签的节点
    var len1=a.length
    var arr1=[]
    for(var i=0;i<len1;i++){
    var obj={}
    var key=$(a[i]).text().toString()
    var value=$(a[i]).attr('href')
    obj[key]=value
    arr1.push(obj)
    }
    JSON.stringify(arr1)//以json的格式存储数据
    

    结果

    left.png
    "[{"家用电器":"//jiadian.jd.com"},{"手机":"//shouji.jd.com/"},{"运营商":"//wt.jd.com"},{"数码":"//shuma.jd.com/"},{"电脑":"//diannao.jd.com/"},{"办公":"//bg.jd.com"},{"家居":"//channel.jd.com/home.html"},{"家具":"//channel.jd.com/furniture.html"},{"家装":"//channel.jd.com/decoration.html"},{"厨具":"//channel.jd.com/kitchenware.html"},{"男装":"//channel.jd.com/1315-1342.html"},{"女装":"//channel.jd.com/1315-1343.html"},{"童装":"//channel.jd.com/children.html"},{"内衣":"//channel.jd.com/1315-1345.html"},{"美妆个护":"//channel.jd.com/beauty.html"},{"宠物":"//channel.jd.com/pet.html"},{"女鞋":"//channel.jd.com/womensshoes.html"},{"箱包":"//channel.jd.com/bag.html"},{"钟表":"//channel.jd.com/watch.html"},{"珠宝":"//channel.jd.com/jewellery.html"},{"男鞋":"//channel.jd.com/mensshoes.html"},{"运动":"//channel.jd.com/yundongcheng.html"},{"户外":"//channel.jd.com/outdoor.html"},{"汽车":"//car.jd.com/"},{"汽车用品":"//che.jd.com/"},{"母婴":"//baby.jd.com"},{"玩具乐器":"//toy.jd.com/"},{"食品":"//channel.jd.com/food.html"},{"酒类":"//jiu.jd.com"},{"生鲜":"//fresh.jd.com"},{"特产":"//china.jd.com"},{"礼品鲜花":"//channel.jd.com/1672-2599.html"},{"农资绿植":"//nong.jd.com"},{"医药保健":"//health.jd.com"},{"计生情趣":"//channel.jd.com/9192-9196.html"},{"图书":"//book.jd.com/"},{"音像":"//mvd.jd.com/"},{"电子书":"//e.jd.com/ebook.html"},{"机票":"//jipiao.jd.com/"},{"酒店":"//hotel.jd.com/"},{"旅游":"//trip.jd.com/"},{"生活":"//ish.jd.com/"},{"理财":"//licai.jd.com/"},{"众筹":"//z.jd.com/"},{"白条":"//baitiao.jd.com"},{"保险":"//bao.jd.com/"}]"
    

    获取右边的

    var len2=$('.cate_pop').find('.cate_detail_tit').length
    var brr=[]
    for(var i=0;i<len2;i++){
    
    var obj={};//{电视:[{曲面电视:url},{超薄电视:url}]
    var key=$($('.cate_pop').find('.cate_detail_tit')[i]).text()
    obj[key]=[]
    var con=$($('.cate_pop').find('.cate_detail_tit')[i]).siblings('.cate_detail_con').find('.cate_detail_con_lk')
    for(var j=0;j<con.length;j++){
    var obj1={}
    var key1=$(con[j]).text()
    obj1[key1]=$(con[j]).attr('href')
    obj[key].push(obj1)
    }
    brr.push(obj)
    }
    

    转换成json

    数据格式[{电视:[{曲面电视:url},{超薄电视:url}],...},{空调:[{挂壁:url},{座机:url}],...}]
    
    right.png

    相关文章

      网友评论

          本文标题:面试测试

          本文链接:https://www.haomeiwen.com/subject/ayiidxtx.html