zoukankan      html  css  js  c++  java
  • [Javasript] 同时实现单击和双击事件

    在同一个元素上同时绑定单击和双击事件:

    JavaScript

    <script type="text/javascript">
        var timer = 0;
        var delay = 200;
        var prevent = false;
        function singleClick(id)
        {
            clearTimeout(timer);
            timer = setTimeout(function() {
            if (!prevent) {copy(id);}
            prevent = false;
            },delay);    //“200”单位是毫秒
        }
    
        function dbClick(id)
        {
            clearTimeout(timer);
            prevent = true;
            edit(id);
        }
    
        function copy(id)
        {
            var textInComment = document.getElementById(id).title;
            var oInput = document.createElement('input');
            oInput.value = textInComment;
            document.body.appendChild(oInput);
            oInput.select(); // 选择对象
            document.execCommand("Copy"); // 执行浏览器复制命令
            oInput.className = 'oInput';
            oInput.style.display='none';
            alert("Copy success, you can paste it!");
        }
    
        function edit(id)
        {
            var textInComment = document.getElementById(id).title;
            var name=prompt("输入的内容","");
            if (name!=null && name!="") {
                alert("你输入的是" + name);
            }
        }
    </script>
    

    Html

    <img src="{% static 'images/comment.png' %}" id="{{forloop.parentloop.counter}}{{forloop.counter}}" onclick="singleClick('{{forloop.parentloop.counter}}{{forloop.counter}}')" ondblclick="dbClick('{{forloop.parentloop.counter}}{{forloop.counter}}')" title='{{v2.comment}}' height="30" width="30" >
    

      

  • 相关阅读:
    用代码初始化AE控件许可
    打开shpfile,mdb,sde工作空间
    UESTC_Tournament CDOJ 124
    UESTC_Little Deer and Blue Cat CDOJ 1025
    UESTC_Judgment Day CDOJ 11
    UESTC_One Step Two Steps CDOJ 1027
    UESTC_In Galgame We Trust CDOJ 10
    UESTC_贪吃蛇 CDOJ 709
    UESTC_冰雪奇缘 CDOJ 843
    java 常用API 时间
  • 原文地址:https://www.cnblogs.com/MasterMonkInTemple/p/10700589.html
Copyright © 2011-2022 走看看