if (op == "edit") {
                var pid = -1;
                $("#btnSave").val("   修改   ");
                $.ajax({
                    type: "post",
                    url: "../ajax/ModuleManager.ashx",
                    dataType: 'json',
                    data: { op: "showOne", mid: modeId },
                    success: function(res) {
                        $(res["ShowOne"]).each(function(i, node) {
                            $("#txtName").val(node.ModuleName);
                            $("#txtUrl").val(node.ModuleUrl);
                            $("#txtDes").val(node.ModuleDes);
                            level = node.ModuleType;
                            pid = node.ModuleParentID;
                            showSr(level, pid);
                        });                    }
                });            }
 function showSr(l, p) {
            if (l == 1) {
                $("#dfirst").show();
                $("#dsecond").hide();
                $("#dthird").hide();
                $("#first").attr("checked", "true");
            }
            else if (l == 2) {
                $("#dfirst").hide();
                $("#dsecond").show();
                $("#dthird").hide();
                $("#second").attr("checked", "true");
                GetFistNode();
                showSf(p);            } else if (l == 3) {
                $("#dfirst").hide();
                $("#dsecond").show();
                $("#dthird").show();
                $("#third").attr("checked", "true");
                GetFistNode();
                GetSecondNode();
                showSf(p);
              //  showSs();
            } function showSf(p) {
            $.ajax({
                type: "post",
                url: "../ajax/ModuleManager.ashx",
                dataType: 'json',
                data: { op: "showOne", mid: p },
                success: function(res) {
                    $(res["ShowOne"]).each(function(i, node) {
                        $("#sfirst").val(node.ModuleName);
                        alert(node.ModuleName);
                    });
                }
            });
        }
 <td>
                <input type="radio" id="first" name="1" />第一级模块&nbsp;&nbsp;&nbsp;
                <input type="radio" id="second" name="1" />第二级模块&nbsp;&nbsp;&nbsp;
                <input type="radio" id="third" name="1" />第三级模块

解决方案 »

  1.   

      <div id="dfirst">
                        第一级目录无父节点</div>
                    <div id="dsecond">
                        <select id="sfirst">
                        </select>
                    </div>
                    <div id="dthird">
                        <select id="sSecond">
                        </select>
                    </div>
                </td>
                <td id="wslevel" align="left">
                </td>
      

  2.   

       问题是
    <select id="firstdName">
    <option value="1">sss</option >
    <option value="2">aaa</option >
    <option value="3">bbb</option >
    </select>
    如果传过来的是 2  如何使用JQ让2 选中?
      

  3.   

    上面的 option 是我动态产生的 
      我要它的值选中某个 用JQ实现
      

  4.   

    这个貌似要循环判断
    for(var i=0;i<$("firstdName").options.length;i++)
    {
    if($("firstdName").options[i].value=="2")
    {
    $("firstdName").options[i.selected="selected";//Jquery我不会,不知道$("firstdName")这样写错没
    break;
    }
    }
    好像没有直接能根据Value值让下拉列表直接选中谁的方法。
      

  5.   

    $("firstdName").options[i]少了个中括号.selected="selected";
      

  6.   


    function show(num) {
      $("#firstdName>option").val(function() {
         if ($(this).val() == num) {
             $(this).attr("selected", "true");
         }
      })
     }
      

  7.   


    昨天你问的时候就回了啊,实验过的,要选择的项的value值传进这个方法就行了
      

  8.   


    如果你自动添加的select的value和你的例子一样,即value为顺序值,则:
    function dosele(int)
    {
    document.getElementById("firstdName").options[int-1].selected=true;
    }如果不是这种对应关系
    function dosele(int)
    {
    var objs=document.getElementById("firstdName").options;
    for (i=0;i<objs.length;i++)
    {
    if (objs[i].value==int) bojs[i].selected=true;
    }
    }
      

  9.   

    document.getElementById("firstdName").value = 2;
      

  10.   

    帖子太长,没细看
    document.getElementById("firstdName").value='2';无奈结贴?啥意思
      

  11.   


            function showSf(p) {
                $.ajax({
                    type: "post",
                    url: "../ajax/ModuleManager.ashx",
                    dataType: 'json',
                    data: { op: "showOne", mid: p },
                    success: function(res) {
                    $("#sfirst option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
                    GetSecondNode(res["ShowOne"][0].ModuleID);
                    }
                });
            }        function showSs(p) {
                $.ajax({
                    type: "post",
                    url: "../ajax/ModuleManager.ashx",
                    dataType: 'json',
                    data: { op: "showOne", mid: p },
                    success: function(res) {
                        showSf(res["ShowOne"][0].ModuleParentID);
                        $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
                    }
                });
            }
     $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
    我调用第二个方法 showSs(p) 第一个方法中的  $("#sfirst option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);  执行了 
    第二个方法 的   $("#sfirst option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
    却没执行是什么道理 ?
      

  12.   

    第二个问题,你应该将你的调用代码贴出来,这里没有发现什么问题
    第一个问题,用JQ比较好解决
    $("#firstdName").val("2");
      

  13.   


    $("#firstdName").val("2");我这样用了  根本就没用 
      

  14.   

    不知道
    showSf(res["ShowOne"][0].ModuleParentID);
    $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
    你把这两句前后换下试试呢?
      

  15.   


      function showSs(p) {
                $.ajax({
                    type: "post",
                    url: "../ajax/ModuleManager.ashx",
                    dataType: 'json',
                    data: { op: "showOne", mid: p },
                    success: function(res) {
                        showSf(res["ShowOne"][0].ModuleParentID);
                        $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
                    }
                });
    楼主这段代码在哪里调用的?
      

  16.   


    IE8、FireFox的Firebug都可以调试js,下个断点,就可以看出问题,你先看sfirst 这里执行后有没有错误,再看sSecond这里能不能找到相应的对象,也就是第2个下拉
      

  17.   


      
            function showSr(l, p) {
                if (l == 1) {
                    $("#dfirst").show();
                    $("#dsecond").hide();
                    $("#dthird").hide();
                    $("#first").attr("checked", "true");
                }
                else if (l == 2) {
                    $("#dfirst").hide();
                    $("#dsecond").show();
                    $("#dthird").hide();
                    $("#second").attr("checked", "true");
                    GetFistNode();
                    showSf(p);            } else if (l == 3) {
                    $("#dfirst").hide();
                    $("#dsecond").show();
                    $("#dthird").show();
                    $("#third").attr("checked", "true");
                    GetFistNode();
                    showSs(p);
                }
            }
      

  18.   

     是不是因为JS的某些原因 这话没执行啊 
     $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
      

  19.   

    很久没上CSDN了,处女贴啊,高调插入  第二句没执行的话,我的建议是先把res["ShowOne"][0].ModuleID  赋值给一个变量,alert一下,看这个值是什么,IE调试的时候右边也会显示这个值的
      

  20.   

    写好js确实很麻烦,我经常是2天时间就在处理一个JS问题,同情楼主 
      

  21.   

    可以弹出来 res["ShowOne"][0].ModuleID  = 29 
    从结果上看 应该是没错的 
      

  22.   

    那就继续 调试alert ("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").length 这个如果没找到,就是你下拉框的value值不对,
      

  23.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="Sandy(阿非)">
      <META NAME="Keywords" CONTENT="Sandy,阿非">
      <META NAME="Description" CONTENT="">
      <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
     </HEAD> <BODY>
      <select id='sel'>
      <option value='1'>1</option>
        <option value='2'>2</option>
      <option value='3'>3</option>
        <option value='4'>4</option>
      </select>
      <br>
      <hr>
    Method One &nbsp;&nbsp;
    <input type='button' value='2被选中' onclick='MethodOne();'/>
    <hr>
    Method Two &nbsp;&nbsp;
    <input type='button' value='3被选中' onclick='MethodTwo();'/>
      <script>
          function MethodOne()
          {
           $('#sel')[0].value=2;
      }
      function MethodTwo()
          {
           $('#sel option[value=3]').attr("selected","true");
      }
      </script>
     </BODY>
    </HTML>
      

  24.   

    $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);=>alert($("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").val());
      

  25.   

    我记得上回我回了个sql的问题~~~
    你可用分不少嘛!这么用都没用完~
      

  26.   


    function showSs(p) {
                $.ajax({
                    type: "post",
                    url: "../ajax/ModuleManager.ashx",
                    dataType: 'json',
                    data: { op: "showOne", mid: p },
                    success: function(res) {
                        showSf(res["ShowOne"][0].ModuleParentID);
                        $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);//你res["ShowOne"][0].ModuleID 这个得到的值,在sSecond的option中有没有,且看看这个值有没有带空格。因为是从后台得到的数据,如果数据库的类型问题有可能带空格。
    //$("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]")能否找到这个对象,我记得
    //在html中可以这样,$("#sSecond option[value='" + res["ShowOne"][0].ModuleID + "']").attr("selected", "selected");是selected="selected",$("input[attr='value']")
    //里面的value最好加上单引号                }
                });
            }
      

  27.   


    不行  没有定义   $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
    没有用啊 我在获取第一及的时候也是这样写的 $("#sfirst option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
    第一级它选中了 
      

  28.   

    你这段代码我好像见过一次,不过是另外一个问题。
    你的级联效果如果通过cs实现,是一定能行的
    如果通过ashx,我这就没把握了。
    祝愿大家帮你找到好方法!
      

  29.   

    可怜的娃,还没找出来问题吗不行贴代码吧,最后输出的HTML
      

  30.   


    <body>
        <form name="aspnetForm" method="post" action="ModuleInfo.aspx?op=edit&amp;mid=30" id="aspnetForm">
    <div>
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJODk5OTg5MTY2ZGQKmB9JOzBwRUDso2Ee/i26ADcphg==" />
    </div>
     
    <script type="text/javascript"> 
    //<![CDATA[
    var theForm = document.forms['aspnetForm'];
    if (!theForm) {
        theForm = document.aspnetForm;
    }
    function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    //]]>
    </script>
    <script type="text/javascript"> 
    //<![CDATA[
    if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax 客户端框架未能加载。');
    //]]>
    </script>
     
    <script src="/ScriptResource.axd?d=taz9kjotyipL1BfEMLYMIUwcwSt-V39Ps8OjXm-W_z9ojzxqsa9NGQkmRolr275luPKJtc7P3pbajl7PxrrTncl9c2s973ZN4naLy2tp-i0v4hnxeEOMX7buo2F1R0rY0&amp;t=7c2f9dc6" type="text/javascript"></script>
        <div>
            <table border="0" cellpadding="1" cellspacing="1" width="98%">
                <tr>
                    <td>
                        <script type="text/javascript"> 
    //<![CDATA[
    Sys.WebForms.PageRequestManager._initialize('ctl00$ScriptManager1', document.getElementById('aspnetForm'));
    Sys.WebForms.PageRequestManager.getInstance()._updateControls([], [], [], 90);
    //]]>
    </script>
     
                    </td>
                </tr>
                <tr>
                    <td>
                        <table width='98%' border='0' cellpadding='1' cellspacing='1' bgcolor='#CBD8AC' align="center"
                            style="margin-top: 8px">
                            <tr bgcolor='#EEF4EA'>
                                <td background='skin/images/wbg.gif'>
                                    <table border='0' cellpadding='0' cellspacing='0'>
                                        <tr>
                                            <td>
                                                <img src="../skin/images/frame/localGIF.gif" width="20" alt="" />&nbsp;<a href=""
                                                    target="_top">后台管理</a>
                                            </td>
                                            <td>
                                                
        &nbsp;>>&nbsp;<a href="ModuleManager.aspx" target="_top">模块管理</a> &nbsp;>>&nbsp;<a
            href="javascript:void(0);" target="_top">模块信息</a>
     
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td>
                        <table width='98%' border='0' cellpadding='1' cellspacing='1' bgcolor='#CBD8AC' align="center"
                            style="margin-top: 8px">
                            <tr bgcolor='#EEF4EA'>
                                <td background='skin/images/wbg.gif'>
                                    <table border='0' cellpadding='0' cellspacing='0'>
                                        <tr>
                                            <td>
                                                
     
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td>
                        <table width='98%' border='0' cellpadding='0' cellspacing='0' bgcolor='#CBD8AC' align="center"
                            style="margin-top: 8px">
                            <tr bgcolor='#EEF4EA'>
                                <td background="skin/images/wbg.gif" valign="top" >
                                    
        <table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center"
            style="margin-top: 8px">
            <tr align='center' bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor='#FCFDEE';"
                onmouseout="javascript:this.bgColor='#FFFFFF';" height="50px">
                <td>
                </td>
                <td colspan="2" id="title">
                </td>
                <td align="left">
                </td>
            </tr>
            <tr align='center' bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor='#FCFDEE';"
                onmouseout="javascript:this.bgColor='#FFFFFF';">
                <td width="20%">
                </td>
                <td width="20%">
                    模块名字:
                </td>
                <td width="40%">
                    <input type="text" id="txtName" />
                </td>
                <td width="20%" id="wtxtName" align="left">
                </td>
            </tr>
            <tr align='center' bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor='#FCFDEE';"
                onmouseout="javascript:this.bgColor='#FFFFFF';">
                <td>
                </td>
                <td>
                    模块的级别:
                </td>
                <td>
                    <input type="radio" id="first" name="1" />第一级模块&nbsp;&nbsp;&nbsp;
                    <input type="radio" id="second" name="1" />第二级模块&nbsp;&nbsp;&nbsp;
                    <input type="radio" id="third" name="1" />第三级模块
                </td>
                <td id="wlevel" align="left">
                </td>
            </tr>
            <tr align='center' bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor='#FCFDEE';"
                onmouseout="javascript:this.bgColor='#FFFFFF';">
                <td>
                </td>
                <td valign="top">
                    请选择父节点:
                </td>
                <td>
                    <div id="dfirst">
                        第一级目录无父节点
                    </div>
                    <div id="dsecond">
                        第一级模块:
                        <select id="sfirst">
                        </select>
                    </div>
                    <div id="dthird">
                        第二级模块:
                        <select id="sSecond">
                        </select>
                    </div>
                </td>
                <td id="wslevel" align="left">
                </td>
            </tr>
            <tr align='center' bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor='#FCFDEE';"
                onmouseout="javascript:this.bgColor='#FFFFFF';">
                <td>
                </td>
                <td>
                    链接地址:
                </td>
                <td>
                    <input type="text" id="txtUrl" />
                </td>
                <td id="wtxtUrl" align="left">
                </td>
            </tr>
            <tr align='center' bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor='#FCFDEE';"
                onmouseout="javascript:this.bgColor='#FFFFFF';">
                <td>
                </td>
                <td>
                    模块描述:
                </td>
                <td>
                    <textarea id="txtDes" rows="7" cols="50"></textarea>
                </td>
                <td id="wtxtDes">
                </td>
            </tr>
            <tr align='center' bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor='#FCFDEE';"
                onmouseout="javascript:this.bgColor='#FFFFFF';">
                <td>
                </td>
                <td colspan="2">
                    <input type="button" id="btnSave" />
                    &nbsp;&nbsp;&nbsp;<input type="button" id="btnBack" value="   返回   " />
                </td>
                <td>
                </td>
            </tr>
        </table>
     
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
        
     
    <script type="text/javascript"> 
    //<![CDATA[
    Sys.Application.initialize();
    //]]>
    </script>
    </form>
    </body>
    </html>
      

  31.   


    function showSs(p) {
                $.ajax({
                    type: "post",
                    url: "../ajax/ModuleManager.ashx",
                    dataType: 'json',
                    data: { op: "showOne", mid: p },
                    success: function(res) {
                        showSf(res["ShowOne"][0].ModuleParentID);
                        $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);//你res["ShowOne"][0].ModuleID 这个得到的值,在sSecond的option中有没有,且看看这个值有没有带空格。
    //因为是从后台得到的数据,如果数据库的类型问题有可能带空格。
    //$("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]")能否找到这个对象,
    //我记得在html中可以这样,$("#sSecond option[value='" + res["ShowOne"][0].ModuleID + "']").attr("selected", "selected");
    //是selected="selected",$("input[attr='value']")里面的value最好加上单引号                }
                });
            }
      

  32.   

        <script type="text/javascript">
            $(function() {
                var modeId = -1;
                var op = "";
                var level = -1;
                var urlinfo = window.location.href;              //获取当前页面的url
                if (urlinfo == "" || urlinfo == null) {
                    location = "ModuleManager.aspx";
                }
                var len = urlinfo.length;                       //获取url的长度
                var offset = urlinfo.indexOf("?");             //设置参数字符串开始的位置
                if (offset > 0) {
                    var newsidinfo = urlinfo.substr(offset, len); //取出参数字符串 这里会获得类似“id=1”这样的字符串
                    var newsids = newsidinfo.split("=");         //对获得的参数字符串按照“=”进行分割 
                    if (newsids[1].indexOf("&") > 0) {
                        op = newsids[1].split("&")[0];
                    }
                    modeId = newsids[2];
                }
                else {
                    op = "add";
                }
     
                if (op == "edit") {
                    $("#first").attr("disabled", true);
                    $("#second").attr("disabled", true);
                    $("#third").attr("disabled", true);
                    var pid = -1;
                    $("#btnSave").val("   修改   ");
                    $.ajax({
                        type: "post",
                        url: "../ajax/ModuleManager.ashx",
                        dataType: 'json',
                        data: { op: "showOne", mid: modeId },
                        success: function(res) {
                            $(res["ShowOne"]).each(function(i, node) {
                                $("#txtName").val(node.ModuleName);
                                $("#txtUrl").val(node.ModuleUrl);
                                $("#txtDes").val(node.ModuleDes);
                                level = node.ModuleType;
                                pid = node.ModuleParentID;
                                showSr(level, pid);
                            });
     
                        }
                    });
     
                }
                else {
                    op = "add";
                    $("#first").attr("enabled", true);
                    $("#second").attr("enabled", true);
                    $("#third").attr("enabled", true);
                    $("#dfirst").hide();
                    $("#dsecond").hide();
                    $("#dthird").hide();
                    $("#btnSave").val("   添加   ");
                    var level = 0;
                }
                $("#first").bind("click", function() {
                    level = 1;
                    $("#dfirst").show();
                    $("#dsecond").hide();
                    $("#dthird").hide();
                });
     
                $("#second").bind("click", function() {
                    level = 2;
                    $("#dfirst").hide();
                    $("#dsecond").show();
                    $("#dthird").hide();
                    GetFistNode();
                });
     
                $("#third").bind("click", function() {
                    level = 3;
                    $("#dfirst").hide();
                    $("#dsecond").show();
                    $("#dthird").show();
                    GetFistNode();
                    GetSecondNode($("#sfirst").val());
                });
     
                $("#sfirst").bind("change", function() {
                    GetSecondNode($("#sfirst").val());
                });
     
                $("#btnSave").bind("click", function() {
                    $("#wtxtName").html("");
                    $("#wlevel").html("");
                    $("#wtxtUrl").html("");
                    $("#wslevel").html("");
                    var txtName = $("#txtName").val();
     
                    if (txtName == "") {
                        $("#wtxtName").html("<span style='color:Red;'>请输入模块的名称!</span>");
                        return;
                    }
                    if (txtName.length > 5) {
                        $("#wtxtName").html("<span style='color:Red;'>请输入4-5个汉字!</span>");
                        return;
                    }
     
                    if (level == 0) {
                        $("#wlevel").html("<span style='color:Red;'>请选择模块的级别!</span>");
                        return;
                    }
                    if (level > 1) {
                        if ($("#sfirst").val() == "0") {
                            $("#wslevel").html("<span style='color:Red;'>请选择第一级模块!</span>");
                            return;
                        }
                    }
                    if (level == 3) {
                        if ($("#sSecond").val() == "0") {
                            $("#wslevel").html("<span style='color:Red;'>请选择第二级模块!</span>");
                            return;
                        }
     
                        if ($("#txtUrl").val() == "") {
                            $("#wtxtUrl").html("<span style='color:Red;'>请输入链接地址!</span>");
                            return;
                        }
                    }
                    if ($("#txtDes").val().length > 50) {
                        $("#wtxtDes").html("<span style='color:Red;'>描述请不要超过50个汉字!</span>");
                        return;
                    }
     
                    if (op == "add") {
                        $.ajax({
                            url: '../ajax/ModuleManager.ashx',
                            type: 'post',
                            dataType: "json",
                            data: { op: op, level: level, txtName: txtName, firstdName: $("#sfirst").val(), secondName: $("#sSecond").val(), txtLink: $("#txtUrl").val(), txtDes: $("#txtDes").val() },
                            success: function(res) {
                                alert(res.msg);
                                location = "ModuleManager.aspx";
                            },
                            error: function(res) {
                                alert(res);
                            }
                        });
                    }
                    else if (op == "edit") {
                        $.ajax({
                            url: '../ajax/ModuleManager.ashx',
                            type: 'post',
                            dataType: "json",
                            data: { op: op, level: level, modeId: modeId, txtName: txtName, firstdName: $("#sfirst").val(), secondName: $("#sSecond").val(), txtLink: $("#txtUrl").val(), txtDes: $("#txtDes").val() },
                            success: function(res) {
                                alert(res.msg);
                                location = "ModuleManager.aspx";
                            },
                            error: function(res) {
                                alert(res);
                            }
                        });
                    }
     
     
     
     
                });
     
                $("#btnBack").bind("click", function() {
                    location = "ModuleManager.aspx";
                });
     
            });
     
            function showSf(p) {
                $.ajax({
                    type: "post",
                    url: "../ajax/ModuleManager.ashx",
                    dataType: 'json',
                    data: { op: "showOne", mid: p },
                    success: function(res) {
                    $("#sfirst option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
                    GetSecondNode(res["ShowOne"][0].ModuleID);
                    }
                });
            }
     
            function showSs(p) {
                $.ajax({
                    type: "post",
                    url: "../ajax/ModuleManager.ashx",
                    dataType: 'json',
                    data: { op: "showOne", mid: p },
                    success: function(res) {
                    showSf(res["ShowOne"][0].ModuleParentID);
                   
                        $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
                        alert($("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").val());
                    }
                });
            }
     
            function showSr(l, p) {
                if (l == 1) {
                    $("#dfirst").show();
                    $("#dsecond").hide();
                    $("#dthird").hide();
                    $("#first").attr("checked", "true");
                }
                else if (l == 2) {
                    $("#dfirst").hide();
                    $("#dsecond").show();
                    $("#dthird").hide();
                    $("#second").attr("checked", "true");
                    GetFistNode();
                    showSf(p);
     
                } else if (l == 3) {
                    $("#dfirst").hide();
                    $("#dsecond").show();
                    $("#dthird").show();
                    $("#third").attr("checked", "true");
                    GetFistNode();
                    showSs(p);
                }
            }
            function GetFistNode() {
                $.ajax({
                    type: "post",
                    url: "../ajax/ModuleManager.ashx?op=first",
                    dataType: 'json',
                    success: function(res) {
                        var h = "<option value=\"0\">------请选择------</option>";
                        $(res["FirstNode"]).each(function(i, first) {
                            h += "<option value=\"" + first.ModuleID + "\">" + first.ModuleName + "</option>";
                        });
                        $("#sfirst").html(h);
                    }
                });
            }
     
            function GetSecondNode(mid) {
     
                if (mid == "0" || mid == null) {
                    $("#sSecond").html("<option value=\"0\">------请选择------</option>");
                    return;
                }
                $.ajax({
                    type: "post",
                    url: "../ajax/ModuleManager.ashx?op=second&mid=" + mid,
                    dataType: 'json',
                    success: function(res) {
                        var h = "<option value=\"0\">------请选择------</option>";
                        $(res["SecondNode"]).each(function(i, first) {
                            h += "<option value=\"" + first.ModuleID + "\">" + first.ModuleName + "</option>";
                        });
                        $("#sSecond").html(h);
                    }
                });
            }
        </script>
     
      

  33.   

    这里没执行的 我ALERT(res["ShowOne"][0].ModuleID );
    得到的没错
      

  34.   

                  alert(res["ShowOne"][0].ModuleID);
                        $("#sSecond option[value='" + res["ShowOne"][0].ModuleID + "']").attr("selected", true);
                        alert(res["ShowOne"][0].ModuleID);
    俩个都执行了 
      

  35.   

    能贴下返回的json数据吗话说你这个页面怎么还用了 asp.net ajax
      

  36.   

    我随便乱用的  JSON的数据没错啊 第一及默认显示 和第二及的默认显示调用的同一个方法啊 
      既然第一及可以显示  说明 JSON的数据没错啊 
      

  37.   

    看了一半天,终于大致明白你写的意思了GetFistNode();
    GetSecondNode($("#sfirst").val());GetFistNode();
    showSf(p);
    .......你那个showone是返回的默认值吧?为什么不直接写在GetSecondNode GetFistNode里呢?
    你是先调GetSecondNode 绑定下拉框 , 然后在再获取默认值,本来是可以的,关键是你这样写不对你写的是同时调两个ajax,会一个前一个后的,并不一定是写在下面的那个方法会后执行,你的执行showSf的时候,如果没有获取到第一个的值,当然就选不中了
    可以在绑定下拉框数据的事件里写 showSf(p); showSs你看看是不是这个原因
      

  38.   

    GetSecondNode  GetFistNode 是绑定的第一及菜单 和第二及菜单 
     $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);关键是这个代码失效了  就是没做用  
    res["ShowOne"][0].ModuleID 
      这个东西到是没错返回的数据是正确的 
    可哪句话就问题很大了
     感觉没执行  应该说根本就好象没执行一样                    
      

  39.   

    你没明白我的意思啊?首先 你的res["ShowOne"][0].ModuleID 肯定是有的原因是 你把绑定下拉框和 给他赋默认值是同步进行了两个方法你都是用的ajax调用的GetSecondNode() 这个方法是绑定下拉框,当数据返回成功后他才会绑定 
    showSf() 写在上个方法的下一行,当数据返回成功后他会去遍历sSecond 的下拉框,然后绑定默认值由于ajax是异步执行的,所以你这样写并不敢保证你第2步一定是第一步完全结束后才操作的,明白了吗你这句
    $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);由于sSecond 下拉框还没有绑定完,所以根本找不到 res["ShowOne"][0].ModuleID 这个值,alert($("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").val()) 肯定要报错,因为没找到
      

  40.   

    可以把你获取默认值的那个ajax方法放到GetSecondNode GetFistNode  方法里面,放success里面,当数据下载成功绑定成功后,再去执行获取默认值你这样设计不是很好,应该是获取下拉框值的时候同时也获取默认值,不过都做到这里来了,就别去改那些小细节了 
      

  41.   

    我的意见 你还是先判断 你第2个方法执行的时候 下拉框的值到底改变了没有比如 alert($("#sSecond ").html()) 确定是这个原因了再想办法解决如果是,完全可以考虑用全局变量来解决你说的这个问题嘛
      

  42.   

    写在这里,我知道你晕了
    function showSs(p) {
    $.ajax({
    type: "post",
    url: "../ajax/ModuleManager.ashx",
    dataType: 'json',
    data: { op: "showOne", mid: p },
    success: function(res) {
    showSf(res["ShowOne"][0].ModuleParentID);
       
    $("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").attr("selected", true);
    //alert($("#sSecond option[value=" + res["ShowOne"][0].ModuleID + "]").val());
    //这里看一下第2个下拉框的值到底改变了没有
    alert($("#sSecond ").html()) 
    }
    });
    }