//可以保存为html文件,然后用IE打开看效果,一切正常;再用火狐浏览器打开就可以看到在firefox浏览器不行,请高手帮找出原因改正,谢谢!
<html>
<head>
<SCRIPT language=JavaScript>
function Dsy() { this.Items = {}; }
Dsy.prototype.add = function(id,iArray) { this.Items[id] = iArray; } 
Dsy.prototype.Exists = function(id) { if(typeof(this.Items[id]) == "undefined") return false; return true; };
function change(v){
var str="0";
var aTemp
for(i=0;i<v;i++){  str+=("_"+(document.getElementById(s[i]).selectedIndex-1))};
var ss=document.getElementById(s[v]);
with(ss){
length = 0;
aTemp = opt0[v].split("|")
options[0]=new Option(aTemp[0],aTemp[1]);
if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
{
if(dsy.Exists(str)){
ar = dsy.Items[str];
for(i=0;i<ar.length;i++)
{
aTemp = ar[i].split("|");
options[length]=new Option(aTemp[0],aTemp[1]);
}
if(v)options[0].selected = true;
}
}
if(++v<s.length){change(v);}
}
}
var dsy = new Dsy();
dsy.add("0_0_0",["东城区|110101","西城区|110102","海淀区|110108"]); 
dsy.add("0_0_1",["密云县|110228","延庆县|110229"]); 
dsy.add("0_0",["市辖区|110100","北京县|110200"]); 
dsy.add("0_1_0",["和平区|120101","河东区|120102","河西区|120103"]); 
dsy.add("0_1_1",["宁河县|120221","静海县|120223","蓟县|120225"]); 
dsy.add("0_1",["市辖区|120100","天津县|120200"]); 
dsy.add("0",["北京市|110000","天津市|120000"]); 
<!--
var s=["province","city","region"];
var opt0 = ["--请选择所在省--|","--请选择市--|","--请选择区--|"];
function setup()
{
for(i=0;i<s.length-1;i++)
document.getElementById(s[i]).onchange=new Function("change("+(i+1)+");document.getElementById('identity').innerText=this.value");
change(0);
}
//-->
</SCRIPT>
</head>
<body onload=setup()>
请选择地区:<select name="province"></select> <select name="city"></select> <select name="region"></select> 区段为:<input type="text" id="identity" name="mm" value=""> 
</body> 
</html>

解决方案 »

  1.   

    ie有innerText,火狐是没有的。可以用innerHTML代替
      

  2.   

    重写 innertext  
     
    if(window.navigator.userAgent.toLowerCase().indexOf("msie")==0){ //firefox innerText   
       HTMLElement.prototype.__defineGetter__(     "innerText",  
        function(){  
         var anyString = "";  
         var childS = this.childNodes;  
         for(var i=0; i<childS.length; i++) {  
          if(childS[i].nodeType==1)  
           anyString += childS[i].tagName=="BR" ? '\n' : childS[i].textContent;  
          else if(childS[i].nodeType==3)  
           anyString += childS[i].nodeValue;  
         }  
         return anyString;  
        }  
       );  
       HTMLElement.prototype.__defineSetter__(     "innerText",  
        function(sText){  
         this.textContent=sText;  
        }  
       );  
    }   
      

  3.   


    请选择地区:
    <select name="province" id="province"></select> 
    <select name="city" id="city"></select> 
    <select  name="region" id="region"></select> 
    区段为:<input type="text" id="identity" name="mm" value="">  
    给每个select都加上id
      

  4.   

    <html>
    <head>
    <SCRIPT language=JavaScript>
    alert(22);
    function Dsy() { this.Items = {}; } Dsy.prototype.add = function(id,iArray) { this.Items[id] = iArray; }   Dsy.prototype.Exists = function(id) { 
    if(typeof(this.Items[id]) == "undefined") 
    return false; 
    return  true; 
    }; function change(v){
    var str="0";
    var aTemp
    for(i=0;i<v;i++){
    str+=("_"+(document.getElementById(s[i]).selectedIndex-1))
    };
    var ss=document.getElementById(s[v]);
    // alert("ss:"+ss.innerHTML);
    with(ss){
    length = 0;
    aTemp = opt0[v].split("|")
    options[0]=new Option(aTemp[0],aTemp[1]);
    //当v是0   
    if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
    {
    if(dsy.Exists(str)){
    ar = dsy.Items[str];
    for(i=0;i<ar.length;i++)
    {
    aTemp = ar[i].split("|");
    options[length]=new Option(aTemp[0],aTemp[1]);
    }
    if(v)options[0].selected = true;
    }
    }
    if(++v<s.length){change(v);}
    }
    }
    var dsy = new Dsy();
    dsy.add("0_0_0",["东城区|110101","西城区|110102","海淀区|110108"]);  
    dsy.add("0_0_1",["密云县|110228","延庆县|110229"]);  
    dsy.add("0_0",["市辖区|110100","北京县|110200"]);  
    dsy.add("0_1_0",["和平区|120101","河东区|120102","河西区|120103"]);  
    dsy.add("0_1_1",["宁河县|120221","静海县|120223","蓟县|120225"]);  
    dsy.add("0_1",["市辖区|120100","天津县|120200"]);  
    dsy.add("0",["北京市|110000","天津市|120000"]);  
    <!--
    var s=["province","city","region"];
    var opt0 = ["--请选择所在省--|","--请选择市--|","--请选择区--|"];
    //加载执行这个方法
    function setup()
    {
    for(i=0;i<s.length-1;i++)
    document.getElementById(s[i]).onchange=new Function("change("+(i+1)+");alert(this.value);document.getElementById('identity').value=this.value");
    change(0);
    }
    //-->
    </SCRIPT>
    </head>
    <body onload=setup()>
    请选择地区:
    <select name="province" id="province"></select> 
    <select name="city" id="city"></select> 
    <select  name="region" id="region"></select> 
    区段为:<input type="text" id="identity" name="mm" value="">  
    </body>  
    </html>
      

  5.   


    <html>
    <head>
    <SCRIPT language=JavaScript>
    alert(22);
    function Dsy() { this.Items = {}; } Dsy.prototype.add = function(id,iArray) { this.Items[id] = iArray; }   Dsy.prototype.Exists = function(id) { 
    if(typeof(this.Items[id]) == "undefined") 
    return false; 
    return  true; 
    }; function change(v){
    var str="0";
    var aTemp
    for(i=0;i<v;i++){
    str+=("_"+(document.getElementById(s[i]).selectedIndex-1))
    };
    var ss=document.getElementById(s[v]);
    // alert("ss:"+ss.innerHTML);
    with(ss){
    length = 0;
    aTemp = opt0[v].split("|")
    options[0]=new Option(aTemp[0],aTemp[1]);
    //当v是0   
    if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
    {
    if(dsy.Exists(str)){
    ar = dsy.Items[str];
    for(i=0;i<ar.length;i++)
    {
    aTemp = ar[i].split("|");
    options[length]=new Option(aTemp[0],aTemp[1]);
    }
    if(v)options[0].selected = true;
    }
    }
    if(++v<s.length){change(v);}
    }
    }
    var dsy = new Dsy();
    dsy.add("0_0_0",["东城区|110101","西城区|110102","海淀区|110108"]);  
    dsy.add("0_0_1",["密云县|110228","延庆县|110229"]);  
    dsy.add("0_0",["市辖区|110100","北京县|110200"]);  
    dsy.add("0_1_0",["和平区|120101","河东区|120102","河西区|120103"]);  
    dsy.add("0_1_1",["宁河县|120221","静海县|120223","蓟县|120225"]);  
    dsy.add("0_1",["市辖区|120100","天津县|120200"]);  
    dsy.add("0",["北京市|110000","天津市|120000"]);  
    <!--
    var s=["province","city","region"];
    var opt0 = ["--请选择所在省--|","--请选择市--|","--请选择区--|"];
    //加载执行这个方法
    function setup()
    {
    for(i=0;i<s.length-1;i++)
    document.getElementById(s[i]).onchange=new Function("change("+(i+1)+");alert(this.value);document.getElementById('identity').value=this.value");
    change(0);
    }
    //-->
    </SCRIPT>
    </head>
    <body onload=setup()>
    请选择地区:
    <select name="province" id="province"></select> 
    <select name="city" id="city"></select> 
    <select  name="region" id="region"></select> 
    区段为:<input type="text" id="identity" name="mm" value="">  
    </body>  
    </html>