2013-01-11 106 views
0

I have a php application in which the web page displayed to the user. The page has some links "Edit", "Rename", etc.無法理解元素的<A HREF> tag and javascript call

When the user clicks on the link a dialogbox prompts. The dialogbox is nothing but a HTML <div> form that gets instantly displayed when the user clicks on the "Rename" or "Edit" link.

When I looked at the html source code (i.e. view -> source in Internet Explorer) I found the following Javascript and HTML code

<a class="update renameButton" href="javascript:void(0);">Rename</a> 

I'm unable to understand how the dialogbox gets promted with the above code.

I expected the code to be something like the following:

<a class="update" onclick='rename();' href="javascript:void(0);">Rename</a> 

Can someone help me understand this?

+0

如果這是你自己的代碼,你可能會知道它 –

回答

3

事件處理程序最有可能綁定到其他地方的元素(可能來自包含的JavaScript文件)。例如:

document.getElementsByClassName("update")[0].addEventListener("click", function() { 
    // Do something on click of the first `.update` element 
}, false); 
0

你不應該在html中設置事件監聽器,就像onclick一樣。 頁面向對象註冊一個事件監聽器。例如與像jQuery一樣的庫。

-1

你絕對正確!期望這樣的事情是非常自然的,除了還有其他方法將事件綁定到對象。如果你檢查頁面上的JavaScript代碼,我相信你會發現可能看起來像$('a.renameButton')。click(function(){}); (如果該網站使用jQuery)或類似的東西,綁定該特定標記的onclick事件來執行某些特定操作。

相關問題