-4

このスクリプトを編集してください:

クリック後に表示されるポップアップ ボックスを削除したいのですが、誰かがボタンをクリックしたときに特定の URL にリダイレクトするようにしたいのですか?

    <!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>

助けてください、または少なくともこれを行うスクリプトを教えてください

4

3 に答える 3

1

このブロックからアラートを削除します:

if(navURL){
   alert(navURL);                    
   window.location.href = navURL;
}

したがって、次のようになります。

if(navURL){                    
   window.location.href = navURL;
}
于 2012-12-27T13:27:33.527 に答える
0

「クリック後に表示されるポップアップボックスを削除したい」というのは、アラートのことですか?を含む行を削除するだけalert()です。

于 2012-12-27T13:29:27.430 に答える
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>
于 2012-12-27T13:29:43.860 に答える