简体   繁体   中英

Code Working with Firefox but not with Chrome, Safari

Following code is working with Firefox browser but onClick is not working with Chrome and Safari.

Is there anything missing in the following code. If anyone can help so that It can work with cross browser.

Thanks.

<html><body><form method="post">
<select>
<option value="aa">Please select</option>
<option value="pst" onClick="populate();">Select Existing State</option>
</select>

<select name="abc" id="example-select" style="width: 160px;"></select>

</form>

<script type="text/javascript" language="javascript">
    var example_array = {state1 : '1# First State', state2 : '2# Secondstate', state3 : '3# Third State'}; 

    function populate() {
        var select = document.getElementById("example-select");
        for(index in example_array) {
            select.options[select.options.length] = new Option(example_array[index], index);
        }
    }
</script>
</body></html>

好onclick 似乎在webkit上有一些问题,尝试用onchange绑定populate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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