解决方案 »

  1.   

    现在的问题是,当加载第二个select数据的时候,在下一步选择它的默认值时,是闪的一下又跳转回了第一个option
      

  2.   

    ID为 select_xxiao_SubDeviceInfo 的 select 先被设置了 selected
    然后又被 ajax 返回的数据覆盖了c.oid 是哪里来的,你想达到什么效果?
      

  3.   


    第一个select是第二个的父节点,我得先设置第一个的默认项$("#select_xxiao_SubDeviceType").find("option[value="+c.deviceType+"]").attr("selected",true);
    然后根据第一个的选择去确定第二个加载那些子节点
     var selectType = $("#select_xxiao_SubDeviceType").val();
            $.post("../SubDeviceInfo_findSubDeviceInfosByTypeId?oid="+selectType,function (obj){
                $("#select_xxiao_SubDeviceInfo").html(obj);
            });   
    那个 c.oid 是一个全局变量,根据用户的点击来确定设置哪个子节点为默认项
     $("#select_xxiao_SubDeviceInfo").find("option[value="+c.oid+"]").attr("selected",true);
    现在的问题是 第二个SELECT的默认值能设置成功,但是在一瞬间就变回了 第一个 option 
    @xuzuning
      

  4.   

    select_xxiao_SubDeviceType 这是第一个 select
    select_xxiao_SubDeviceInfo 这是第二个 select当 select_xxiao_SubDeviceType 的值改变时,select_xxiao_SubDeviceInfo 加载相应的列表不是这样的吗?$("#select_xxiao_SubDeviceType").change(function() {
      var selectType = $(this).val();
      $("#select_xxiao_SubDeviceInfo").load("../SubDeviceInfo_findSubDeviceInfosByTypeId?oid="+selectType);
    });
      

  5.   


    对,加载的时候没有任何问题,只要是设置 SELECTED的时候,设置第二个SELECT的SELECTED的时候本来是已经成功的,但是在一瞬间就变回了 加载项中的 第一个 option
      

  6.   

    select_xxiao_SubDeviceInfo 是后加载的还没选呢,你怎么去设置选中项呢?
      

  7.   

    在这个页面还有个表单,是让用户点击 然后再上面的俩个SELECT中显示 表单中的数据,让俩个都选中表单中的数据。那该怎么办?
      

  8.   

    我想你得先理清一下思路
    比如
    列表1选中A时,列表2是对应的a1,a2,a3,此时你可能选了a2并保存起来
    然后列表1由选了B,列表2变成对应的b1,b2,b3,那么就说列表2默认选中了b2,这总是说不过去的吧?
      

  9.   

    倒是不会出现这样的问题,option的value中存的是唯一ID。怎么才能让他刚刚加载出来,就能设置默认选中呢? 
    大神,帮帮忙,周末加班不易啊。
      

  10.   

    $("#select_xxiao_SubDeviceInfo").load("../SubDeviceInfo_findSubDeviceInfosByTypeId?oid="+selectType, {}, function() {
    在这里设置
    });按你首贴的代码
    $.post("../SubDeviceInfo_findSubDeviceInfosByTypeId?oid="+selectType,function (obj){
                $("#select_xxiao_SubDeviceInfo").html(obj);
                在这里设置
            });