标题:我的四级联动下拉列表怎么改二级联动呀,请高手指教~~急
只看楼主
fszyhzg
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-2-23
结帖率:0
 问题点数:0 回复次数:0 
我的四级联动下拉列表怎么改二级联动呀,请高手指教~~急
<script>
var m_oXMLDoc = new ActiveXObject("Microsoft.XMLDOM");

var m_sBaseSrc = "Tree.asp?ParentCode=";
function BindSelect( strXMLSrc , objSelectName, defaultVal)
{
    m_oXMLDoc.async = true;  
    m_oXMLDoc.onreadystatechange = Function( "fnLoadComplete('" + objSelectName + "', '" + defaultVal + "');" );   
    m_oXMLDoc.load( strXMLSrc );
}

function fnLoadComplete(objSelectName, defaultVal)
{
    var objSelect = document.all[objSelectName];
    var aryXMLNodes;
    var node;
    if (objSelect == null)
        return;
    try
    {
        var iReadyState = m_oXMLDoc.readyState;
    }
    catch(e)
    {
        return;
    }
   
    if(  iReadyState != 4 ) return;
   
    if( m_oXMLDoc != null && m_oXMLDoc.xml != "" )
    {
        objSelect.length = 0;
        aryXMLNodes = m_oXMLDoc.documentElement.selectNodes("TreeNode");
        objSelect.options[0] = new Option("==请选择==");
        for (var i=0; i < aryXMLNodes.length; i++)
        {
            node = aryXMLNodes[i];
            objSelect.options[i+1] = new Option(node.getAttribute("Title"),node.getAttribute("MaterialClassCode"));
        }
        
        if (defaultVal != null && defaultVal != "" && objSelect.length > 1)
        {
            SetSelectedValue(objSelect, defaultVal)
        }
        
        if(objSelect.ChildSelectName != null)
        {
            objSelect.onchange = Function( "var val = this.options[this.selectedIndex].value;BindSelect(m_sBaseSrc+val, '"+objSelect.ChildSelectName+"', '"+defaultVal+"');if(val!='')document.all.MaterialClassCode.value=val;" );   
            objSelect.fireEvent("onchange");            
        }
        else
        {
            objSelect.onchange = Function( "var val = this.options[this.selectedIndex].text;if(val!='')document.all.MaterialClassCode.value=val;" );   
        }
    }
}

function InitSelect(defaultVal)
{
    document.all.MaterialClassCode.value = "";
    BindSelect( m_sBaseSrc + "00", "MaterialClass1", defaultVal);
}

function Equality(val1,val2)
{
    if (val1.length < val2.length || val2 == "")
        return false;
    return (val1.substr(0,val2.length) == val2)
}

function SetSelectedValue(oSel,val)
{
    if (val == null)
        return;
    for(var i=0; i<oSel.length; i++)
    {
        if (Equality(val, oSel.options[i].value))
        {
            oSel.selectedIndex = i;

            if(oSel.ChildSelectName == null)
                oSel.fireEvent("onchange");            
            break;
        }
    }
}

window.onload = function(){InitSelect();}
</script><nobr>
<select name="MaterialClass1" ChildSelectName="MaterialClass2"></select>
<select name="MaterialClass2" ChildSelectName="MaterialClass3"></select>
<select name="MaterialClass3" ChildSelectName="MaterialClass4"></select>
<select name="MaterialClass4"></select>
</nobr>
<input type="text" name="MaterialClassCode">
搜索更多相关主题的帖子: function 
2016-03-22 11:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-462767-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.644069 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved