简体   繁体   English

JS处理下拉框

[英]JS handling drop down boxes

i have this script which allows the users to select from Dropdown 1, and it will fill Dropdown 2 with values. 我有这个脚本,允许用户从下拉列表1中选择,它将使用值填充下拉列表2。 THOUGH the problem here is that once it fills, the original "item" called "-- Välj län först --" disappears, which i do not want it to do. 这里的问题是,一旦它填满,原来的“项目”称为“ - Väljlänförst - ”就会消失,我不想这样做。 I just want the new values to fill up under it. 我只想让新值填满它。 Could someone take a look at the code i supply below and see if there is an easy fix for this? 有人可以看看我在下面提供的代码,看看有一个简单的解决方案吗?

Thanks in advance. 提前致谢。

http://pastebin.com/aqvX222V http://pastebin.com/aqvX222V

See this : Sample 见: 样品

function showSubKommun(subCat,selectObj){
   selectObj.length=kommun[subCat].length+1;
   for(var n=1;n<=kommun[subCat].length;n++){
     selectObj[n].text=kommun[subCat][n-1];
     selectObj[n].value=kommun[subCat][n-1];
   }
}

Try this 尝试这个

function showSubKommun(subCat,selectObj){
    selectObj.length=kommun[subCat].length+1;
    selectObj[0].text=kommun[0][0];
    selectObj[0].value=kommun[0][0];
    for(var n=0;n<kommun[subCat].length;n++){
        selectObj[n+1].text=kommun[subCat][n];
        selectObj[n+1].value=kommun[subCat][n];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM