search

Home  >  Q&A  >  body text

javascript - When double-clicking the checkbox, IE and Google execute it differently, please help!

Like the title, post the code

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
        <script type="text/javascript">
            onload=function(){
                $("input[type='checkbox']").attr('ondblclick', false);  
                var inp=document.getElementsByTagName("input")[0];
                inp.onclick=function(){
                    if(inp.checked){
                        console.log("checked")
                    }else{
                        console.log("no checked")
                    }
                    
                }
            }
        </script>
    </head>
    <body>
        <input type="checkbox" name="" id="" value=""/>
    </body>
</html>

Chrome

IE

Chrome executes click and cancel events, while IE executes two click events. What's going on? Please give me some guidance! ! !
Thank you in advance, brother!

PHPzPHPz2792 days ago494

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-05-18 10:48:09

    IE may differentiate between single and double clicks. If you double-click, it will be processed in the same way as single-click, and it will not become canceled the second time. If the time interval is large enough, the system will think it is two clicks, and this will not happen.

    reply
    0
  • Cancelreply