• 下拉框两级联动


    //1.首先获取第一级菜单选中的值 第一级菜单id=select1

    var val = $("#select1 option:selected").val()

    //2.如果第一级下拉框的值改变 

    $("#select1").change(function(){

    //3.清楚第二级下拉框的数据 第二级下拉框的id=select2

    $("#select2 > option").each(function(){

      i++;

      if(i==1) return;//第一个选项为说明,此处不删除

      $(this).remove();

    })

    });

    //4.使用ajax根据第一级下拉框获取第二级下拉框的数据

    $.ajax({

      data:{id:id},

      url:"XX.do",

      success:function(result){

    //5.将获取的数据拼接成第二级下拉框

      $("#select2").append("<option value="+result.val+">"+result.text+"</option>");

      }

    })

  • 相关阅读:
    第八章 多线程编程
    Linked List Cycle II
    Swap Nodes in Pairs
    Container With Most Water
    Best Time to Buy and Sell Stock III
    Best Time to Buy and Sell Stock II
    Linked List Cycle
    4Sum
    3Sum
    Integer to Roman
  • 原文地址:https://www.cnblogs.com/xy-1988xcl/p/5247222.html
Copyright © 2020-2023  润新知