Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
阻止我的JavaScript显示下拉值?_Javascript - Fatal编程技术网

阻止我的JavaScript显示下拉值?

阻止我的JavaScript显示下拉值?,javascript,Javascript,目前,我的JS代码输出所选内容的值,我如何阻止这种情况发生?我似乎在我的JS代码中丢失了它 我不希望它再写下拉列表的输出 <!-- The first select list --> <select name="slist1" onchange="SList.getSelect('slist2', this.value);"> <option>- - -</option> <option value="amazon">A

目前,我的JS代码输出所选内容的值,我如何阻止这种情况发生?我似乎在我的JS代码中丢失了它

我不希望它再写下拉列表的输出

<!-- The first select list -->
<select name="slist1" onchange="SList.getSelect('slist2', this.value);">
    <option>- - -</option>
    <option value="amazon">Amazon</option>
    <option value="apple">Apple</option>
    <option value="keurig">Keurig</option>
    <option value="nike">Nike</option>
</select>

<!-- Tags for the seccond dropdown list, and for text-content -->
<span id="slist2"></span> <div id="scontent"></div>


<script><!--
    /* Script Double Select Dropdown List, from: coursesweb.net/javascript/ */
    var SList = new Object();             // JS object that stores data for options

    // HERE replace the value with the text you want to be displayed near Select
    var txtsl2 = '';

    /*
    Property with options for the Seccond select list
    The key in this object must be the same with the values of the options added in the first select
    The values in the array associated to each key represent options of the seccond select
    */
    SList.slist2 = {
        "amazon": ['Kindle Fire HD', 'Kindle Charger', 'Kindle Fire HDX'],
        "apple": ['MacBook', 'iMac', 'iPhone', 'iPad'],
        "keurig": ['Platinum', 'Vue'],
        "nike": ['Fuel Band']
    };


    /*
    Property with text-content associated with the options of the 2nd select list
    The key in this object must be the same with the values (options) added in each Array in "slist2" above
    The values of each key represent the content displayed after the user selects an option in 2nd dropdown list
    */

    SList.scontent = {
        "Kindle Fire HD": 'kindlefirehd',
        "Kindle Charger": 'kindlecharg',
        "Kindle Fire HDX": 'kindlefirehdx',
        "MacBook": 'macbook',
        "iMac": 'imac',
        "iPhone": 'iphone',
        "iPad": 'ipad',
        "Platinum": 'platinum',
        "Vue": 'vue',
        "FuelBand": 'fuelband'
    };

    /* From here no need to modify */

    // function to get the dropdown list, or content
    SList.getSelect = function(slist, option) {
        document.getElementById('scontent').innerHTML = '';           // empty option-content

        if(SList[slist][option]) {
            // if option from the last Select, add text-content, else, set dropdown list
            if(slist == 'scontent'){ document.getElementById('scontent').innerHTML = SList[slist][option];
                var selected = SList[slist][option];
                functions[selected]();
            }
            else if(slist == 'slist2') {
                var addata = '<option>- - -</option>';
                for(var i=0; i<SList[slist][option].length; i++) {
                    addata += '<option value="'+SList[slist][option][i]+'">'+SList[slist][option][i]+'</option>';
                }
                document.getElementById('slist2').innerHTML = txtsl2+' <select name="slist2" onchange="SList.getSelect(\'scontent\', this.value);">'+addata+'</select>';
            }
        }
        else if(slist == 'slist2') {
            // empty the tag for 2nd select list
            document.getElementById('slist2').innerHTML = '';
        }
    }

    var functions = {
        kindlefirehd: function(){window.alert("func1 called")},
        kindlecharge: function(){window.alert("func1 called")},
        kindlefirehdx: function(){window.alert("func1 called")},
        macbook: function(){window.alert("func1 called")},
        imac: function(){window.alert("func1 called")},
        iphone: function(){window.alert("func1 called")},
        ipad: function(){window.alert("func1 called")},
        platinum: function(){window.alert("func1 called")},
        vue: function(){window.alert("func1 called")},
        fuelband: function(){window.alert("func1 called")}
    }

</script>

乍一看似乎是这一行

document.getElementById('slist2').innerHTML = txtsl2+' <select name="slist2" onchange="SList.getSelect(\'scontent\', this.value);">'+addata+'</select>';

希望能有帮助。如果需要的话,我将稍后再查看,以给出更全面的答案。

如果您正在谈论第二个选择文本,请参阅span scontent-

在SList.getSelect中,它位于以下代码块中:

        if(SList[slist][option]) {
        // if option from the last Select, add text-content, else, set dropdown list
        if(slist == 'scontent'){ /* from here */ document.getElementById('scontent').innerHTML = SList[slist][option]/* to here */;
            var selected = SList[slist][option];
            functions[selected]();
        }

如果删除我的注释之间的代码,它应该停止将其写入span。

如何输出?到控制台?作为警报?