2008-12-07 14 views
3

如何在SOF的新帖子中執行像「Grippie」這樣的沒有onclick的Javascript函數,如堆棧上的<div class="grippie" style="margin-right: 59px;"/>當您發佈問題或答案時溢出?我得到了一個很好的CSS遊標,它讓我知道可移動的邊緣,但是如何調整字段大小的JavaScript我點擊了'grippie'?如何在SOF的新帖子中執行沒有像'Grippie'這樣的'onclick'的Javascript函數

編輯: 謝謝你的答案,導致jQuery和描述處理程序。 我能請有一個簡單的使用,確定被點擊的元素時,像處理的:

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

或然而,這可能工作?

回答

0

中的JavaScript在網站上使用的監聽點擊事件,並查找元素的ID與正在互動。然後腳本會忽略該事件,或者如果元素ID是需要操作的預期對象之一,則執行一些操作。

3

如果您使用Firefox Web Developer插件查看生成的源代碼,您會發現它使用@grepsedawk提到的TextAreaResizer添加了類「grippie」的DIV。這個DIV具有調整大小的精靈背景,並附有一個點擊處理程序來執行調整大小。

2

我研究了一些我將概述的方法。對於哪個是最好的進一步評論將不勝感激。目標是從生成的源中隱藏「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! 
在我的研究結束

因此,本網站技高一籌解釋得非常好如何在Java事件監聽器可以有效地迷上:http://www.howtocreate.co.uk/tutorials/javascript/domevents

相關問題