Javascript 根据用户从下拉菜单中的选择将用户定向到url

Javascript 根据用户从下拉菜单中的选择将用户定向到url,javascript,drop-down-menu,menu,Javascript,Drop Down Menu,Menu,我找到了一个脚本,可以满足我的需要(下拉菜单),但我希望它能够根据用户从下拉菜单中的选择将用户带到外部/内部url,例如,如果用户选择美国,然后选择纽约,他们将转到url#1,如果选择美国和新泽西,则转到url#2,这就是我想要的全部 剧本: <!DOCTYPE html> <html> <head> <title></title> <meta http-equiv="Content-Type" content="

我找到了一个脚本,可以满足我的需要(下拉菜单),但我希望它能够根据用户从下拉菜单中的选择将用户带到外部/内部url,例如,如果用户选择美国,然后选择纽约,他们将转到url#1,如果选择美国和新泽西,则转到url#2,这就是我想要的全部

剧本:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
        var citiesByState = {
            USA: ["NY","NJ"],
            Singapore: ["taas","naas"]
        }
        function makeSubmenu(value) {
            if(value.length==0) document.getElementById("citySelect").innerHTML = "<option></option>";
            else {
                var citiesOptions = "";
                for(cityId in citiesByState[value]) {
                    citiesOptions+="<option>"+citiesByState[value][cityId]+"</option>";
                }
                document.getElementById("citySelect").innerHTML = citiesOptions;
            }
        }
        function displaySelected() {
            var country = document.getElementById("countrySelect").value;
            var city = document.getElementById("citySelect").value;
            alert(country+"\n"+city);
        }
        function resetSelection() {
            document.getElementById("countrySelect").selectedIndex = 0;
            document.getElementById("citySelect").selectedIndex = 0;
        }
    </script>
</head>
<body onload="resetSelection()">
    <select id="countrySelect" size="1" onchange="makeSubmenu(this.value)">
        <option></option>
        <option>USA</option>
        <option>Singapore</option>
    </select>
    <select id="citySelect" size="1">
        <option></option>
    </select>
    <button onclick="displaySelected()">show selected</button>
</body>
</html>

var Citiesbytate={
美国:[“纽约州”、“新泽西州”],
新加坡:[“taas”、“naas”]
}
函数生成子菜单(值){
if(value.length==0)document.getElementById(“citySelect”).innerHTML=“”;
否则{
var citiesOptions=“”;
for(citiesByState中的cityId[值]){
citiesOptions+=“”+citiesByState[value][cityId]+“”;
}
document.getElementById(“citySelect”).innerHTML=CitieOptions;
}
}
函数displaySelected(){
var country=document.getElementById(“countrySelect”).value;
var city=document.getElementById(“citySelect”).value;
警报(国家+“\n”+城市);
}
函数resetSelection(){
document.getElementById(“countrySelect”)。selectedIndex=0;
document.getElementById(“citySelect”).selectedIndex=0;
}
美国
新加坡
显示选定的
请帮忙


<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
        var citiesByState = {
            "USA": ["NY","NJ"],
            "Singapore": ["taas","naas"]
        }
        var navURLs = {
            "USA": {"NY": "http://www.yahoo.com","NJ": "http://www.google.com"},
            "Singapore": {"taas": "http://www.bing.com","naas": "http://www.ibm.com"}
        }
        function makeSubmenu(value) {
            if(value.length==0) document.getElementById("citySelect").innerHTML = "<option></option>";
            else {
                var citiesOptions = "";
                for(cityId in citiesByState[value]) {
                    citiesOptions+="<option>"+citiesByState[value][cityId]+"</option>";
                }
                document.getElementById("citySelect").innerHTML = citiesOptions;
            }
        }
        function displaySelected() {
            var country = document.getElementById("countrySelect").value;
            var city = document.getElementById("citySelect").value;
            alert(country+"\n"+city);
            navURL = navURLs[country][city];
            if(navURL){
                alert(navURL);                    
                window.location.href = navURL;
            }
        }
        function resetSelection() {
            document.getElementById("countrySelect").selectedIndex = 0;
            document.getElementById("citySelect").selectedIndex = 0;
        }
    </script>
</head>
<body onload="resetSelection()">
    <select id="countrySelect" size="1" onchange="makeSubmenu(this.value)">
        <option></option>
        <option>USA</option>
        <option>Singapore</option>
    </select>
    <select id="citySelect" size="1">
        <option></option>
    </select>
    <button onclick="displaySelected()">show selected</button>
</body>
</html>​
var Citiesbytate={ “美国”:[“纽约”、“新泽西”], “新加坡”:[“taas”、“naas”] } var navURL={ “美国”:{“纽约”:”http://www.yahoo.com,“NJ”:http://www.google.com"}, “新加坡”:{“taas”:”http://www.bing.com“,“naas”:”http://www.ibm.com"} } 函数生成子菜单(值){ if(value.length==0)document.getElementById(“citySelect”).innerHTML=“”; 否则{ var citiesOptions=“”; for(citiesByState中的cityId[值]){ citiesOptions+=“”+citiesByState[value][cityId]+“”; } document.getElementById(“citySelect”).innerHTML=CitieOptions; } } 函数displaySelected(){ var country=document.getElementById(“countrySelect”).value; var city=document.getElementById(“citySelect”).value; 警报(国家+“\n”+城市); navURL=navURL[国家][城市]; 如果(导航URL){ 警报(navURL); window.location.href=navURL; } } 函数resetSelection(){ document.getElementById(“countrySelect”)。selectedIndex=0; document.getElementById(“citySelect”).selectedIndex=0; } 美国 新加坡 显示选定的 ​
谢谢您我非常感谢您的帮助,我是否可以删除单击后立即出现的弹出框?我只希望它只重定向?是的-只需删除行
警报(navURL)