简体   繁体   中英

onclick event is not triggered

Code:

corresponding function does not executed when clicked

<body onload="initialize('2.44','12.331')" onunload="triggerUnLoad()">
        <select>
            <option onclick="initialize('2.44331','2.442211')">-sel places-</option>
            <option onclick="initialize('1.2','1.8')">china</option>
            <option onclick="initialize('1.3','1.2')">brazil</option>        
            <option onclick="initialize('1.4','13.3')">australia</option>
        </select>

Onclick function is not working

In some browsers there is no click event for <option> elements. Instead you should use change event for <select> element:

<select onchange="initialize.apply(null, this.value.split(','));">
    <option value="2.44331,2.442211">-sel places-</option>
    <option value="1.2,1.8">china</option>
    <option value="1.3,1.2">brazil</option>        
    <option value="1.4,13.3">australia</option>
</select>

DEMO: http://jsfiddle.net/SgFKj/

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