简体   繁体   English

无法理解<A HREF>标签和JavaScript调用</a>

[英]Unable to understand <A HREF> tag and javascript call

I have a php application in which the web page displayed to the user. 我有一个php应用程序,其中网页显示给用户。 The page has some links "Edit", "Rename", etc. 该页面具有一些链接“编辑”,“重命名”等。

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. 该对话框不过是HTML <div>表单,当用户单击“重命名”或“编辑”链接时,该表单会立即显示。

When I looked at the html source code (ie view -> source in Internet Explorer) I found the following Javascript and HTML code 当我查看html源代码(即Internet Explorer中的view-> source)时,我发现了以下Javascript和HTML代码

<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? 有人可以帮我理解吗?

<script>元素加载的某些JavaScript可能会将事件处理程序功能绑定到该元素。

The event handler is most likely bound to the element elsewhere (from an included JavaScript file perhaps). 事件处理程序最有可能绑定到其他位置的元素(也许从包含的JavaScript文件中)。 For example: 例如:

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

you should not setup event listeners in html anymore like with onclick . 您不应该再像onclick一样在html中设置事件监听器。 the page registers an event listener to the Object. 该页面将事件侦听器注册到对象。 eg with a library like jQuery. 例如使用类似jQuery的库。

You are absolutely correct! 你是绝对正确的! That is very natural to expect such a thing except that there are other ways to bind an event to an object as well. 除了有其他方式将事件绑定到对象之外,期望发生这种事情也是很自然的。

If you check the JavaScript code on the page I am sure you will find perhaps something that looks like $('a.renameButton').click(function(){}); 如果您检查页面上的JavaScript代码,我相信您会发现可能看起来像$('a.renameButton')。click(function(){});。 (if the site is using jQuery) or something similar that binds the onclick event of that particular tag to perform some specific actions. (如果该网站使用的是jQuery)或绑定该特定标签的onclick事件以执行某些特定操作的类似内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM