代码之家  ›  专栏  ›  技术社区  ›  Supernovah

在SOF上的一篇新文章中,如何在没有“onclick”的情况下执行Javascript函数

  •  3
  • Supernovah  · 技术社区  · 16 年前

    onclick 就像在SOF上的一个新帖子中的“gripie”,比如 <div class="grippie" style="margin-right: 59px;"/ >当您发布问题或答案时堆栈溢出?我得到了一个很好的CSS光标,它让我知道了可移动的边,但是JavaScript如何调整字段的大小,从而发现我点击了“grippie”?

    编辑: 感谢您对jQuery的回答,并描述了处理程序。 我能简单地使用一下决定何时单击元素的处理程序吗,比如:

    addListener('myElement',performFunction();).onclick;  
    

    4 回复  |  直到 12 年前
        1
  •  3
  •   tvanfosson    16 年前

    如果使用Firefox Web开发插件查看生成的源代码,您会看到它使用@grepsedawk提到的TextAreaResizer添加了一个类“grippie”的DIV。这个DIV有一个背景的resize sprite,并附加了一个执行resize的click处理程序。

        3
  •  2
  •   Supernovah    16 年前

    我已经研究了一些我将概述的方法。如有进一步意见,请指正。目标是从生成的源代码中隐藏“onClick”侦听器。

    document.getElementById('ID').addEventListener('click',function();,false);  
    //Problems: Has to be terminated and false/true is something tricky I don't understand yet (please see link I post)
    
    document.getElementById('ID').onclick = function();
    //Problems: Cannot be terminated directly and heirachy issue where function including 'this' keyword applies to the child divs or something (please again see link I post)
    
    //an iterartion of setInterval(checkFunction,interval);
    //Problems: Very very slow and in most cases requires an onClick to check for a change anyway!
    

    http://www.howtocreate.co.uk/tutorials/javascript/domevents

        4
  •  0
  •   William Holroyd    16 年前

    网站上使用的JavaScript监听click事件并查找与之交互的元素的ID。然后,如果元素ID是需要操作的预期对象之一,脚本将忽略事件或执行某些操作。