• $.each()方法,其实挺不错的


    例子为主

    html主要代码

     <div class="fl search">厂商:<select id="firms"><option>请选择</option></select> 品牌:<select id="brandmark"><option>请选择</option></select> 型号:<select id="type"><option>请选择</option></select>

    js:

    $(function(){

    function init(obj){
    return $(obj).html("<option>请选择</option>");
    }
    var goodsData = {
    小米: {小米:"小米3,小米4",红米:"红米note,红米note2"},
    苹果: {iphone:"iphone5,iphone6",ipad:"ipad1,ipad2"},
    魅族: {魅族:"魅族1,魅族2",魅蓝:"魅蓝1,魅蓝note"}
    };
    var f = false;
    var b = false;
    var t = false;
    $.each(goodsData,function(fs){
    $('#firms').append("<option>"+fs+"</option>");

    });
    $('#firms').change(function(){
    f = true;
    init("#brandmark");
    init("#type");
    $.each(goodsData,function(fs,bo){

    if($('#firms option:selected').text() == fs){
    $.each(bo,function(bd,tp){
    $('#brandmark').append("<option>"+bd+"</option>");
    });
    $('#brandmark').change(function(){
    init("#type");
    b = true;
    $.each(bo,function(bd,tp){
    if($('#brandmark option:selected').text() == bd){
    $.each(tp.split(","),function(){
    $('#type').append("<option>"+this+"</option>")
    });
    }
    });
    $('#type').change(function(){
    t = true;
    });
    });
    }
    });
    });
    $('#searchBtn').click(function(){
    if(f&&b&&t){
    var str = "你选择的厂商:";
    str += $('#firms option:selected').text();
    str +="&nbsp;你选择的品牌:";
    str += $('#brandmarkm option:selected').text();
    str +="&nbsp;你选择的型号:";
    str += $('#type option:selected').text();
    $('.showdata').show().html(str);
    }else if(f&&!b&&!t){
    $('.showdata').show().html("请选择品牌和型号");
    }else if(f&&b&&!t){
    $('.showdata').show().html("请选择型号");
    }else{
    $('.showdata').show().html("请选择商品");
    }
    });
    });

  • 相关阅读:
    最小费用最大流问题
    成大事必备9种能力、9种手段、9种心态
    转 fpga学习经验2
    算法 FFT理论1
    FPGA进阶之路1
    FPGA:亲和力激活竞争力
    1030 又回来了
    转 fpga学习经验1
    调查:近半大学生愿接受15002000元月薪
    转 观点:哪些人适合做FPGA开发(精华)
  • 原文地址:https://www.cnblogs.com/Ushadow/p/5678524.html
Copyright © 2020-2023  润新知