简体   繁体   中英

javascript works in Chrome does not work in IE

In Chrome browser, when you click on CloudCover on this web page, a description is revealed below. In IE the description is not revealed. Any suggestions to make this work in IE?

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>min test</title>
        <script type='text/javascript'>
            function showDescription (sel) {
                var myVarDescip, myVarTEXT;
                var myVar = (sel.value);
                document.getElementById('putDescriptionHere').innerHTML = "";
                myVarDescip = (myVar + "Descrip");
                myVarTEXT = document.getElementById(myVarDescip).innerHTML;
                document.getElementById('putDescriptionHere').innerHTML = myVarTEXT;
            }
        </script>
    </head>
    <body>
        <select id="destSelect" size="3" multiple="multiple">
            <option value="CloudCover" onclick="showDescription(this);">Cloud Cover</option>
        </select>
        <div id="CloudCoverDescrip" style="display: none">
            <b>Cloud Cover:</b> The percentage of sky occluded by clouds.
        </div>
        <div id="putDescriptionHere"></div>
    </body>
</html>

You can't attach mouse events on options in IE, so the click never fires.

Use the onchange event on the select instead

<select id="destSelect" size="3" multiple="multiple" onchange="showDescription(this);">

FIDDLE

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