JavaScript option onclick event IE solution compatible ie,firefox_ form effects

Source: Internet
Author: User
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <ptml> <pead> <title>select-option on Click </title> <script type= "Text/javascript" > Function Simoptionclick4ie () {var evt=window.event; var selectobj=evt?evt.srcelement:null; IE only if (evt && selectobj && evt.offsety && evt.button!=2 && (evt.offsety > Sel Ectobj.offsetheight | | evt.offsety<0)) {//Record the original selected var oldidx = Selectobj.selectedindex; settimeout (function () {var option=selectobj.options[selectobj.selectedindex]; At this point, you can judge whether the oldidx equals Selectobj.selectedindex//To determine if the user clicked the same option, and then do different processing. Showoptionvalue (option)}, 60); } function Showoptionvalue (opt,msg) {//alert (' AA '); var now=new Date (); var dt= (1900+now.getyear ()) + '-' + (Now.getmonth () +1) + '-' +now.getdate () + ' +now.gethours () + ': ' +now.gethours () + ': ' + Now.getseconds () + '. ' +now.getmilliseconds (); var Resultzone=document.getelementbyid (' Reslut '); ResultZone.style.margin= "10px"; Resultzone.innerhtml=dt + "When clicked on:" + (opt.text + ' = ' +opt.value); } </script> </pead> <body> <select onclick= "Simoptionclick4ie ()" Arial "; font-size:13px; Color: #565553; Font-style:normal; Font-weight:normal; Text-decoration:none "> <!--below onclick=" Showoptionvalue (this) is prepared for FF and opera--> <option value= "1" onc Lick= "Showoptionvalue (This)" >aaaaa</option> <option value= "2" onclick= "Showoptionvalue (This)" > Bbbbb</option> <option value= "3" onclick= "Showoptionvalue (This)" >ccccc</option> </select> & Lt;div id= "Reslut" ></div> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Run the test.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.