在不使用"onclick"的情况下弹出上下文菜单. [英] popping up a context menu without using "onclick"

查看:105
本文介绍了在不使用"onclick"的情况下弹出上下文菜单.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试创建一个简单的基于Ajax的弹出菜单或上下文菜单(类似于 easymenu obout)

(控件的)用户通过添加菜单项(在服务器端)来创建菜单,并指定将使菜单弹出的触发器(通过javascript),但是与弹出控件不同,它可以具有多个触发器. />
我的问题是-什么是让菜单知道应该弹出的好方法?

我将触发器的ID保留在数组中.

我尝试在每个触发器上添加一个"onclick ="menu.pop(x,y)"",但这不是一个好主意,因为"onclick"中可能已经包含一些代码(例如"return false;").在某些情况下).

我看到obout的菜单没有添加"onclick"事件,但是无法弄清楚它们到底做了什么...

有什么建议吗?

在此先谢谢您,

Oren

Hi,

I''m trying to create a simple ajax based popup-menu or context-menu (similar to the easymenu by obout)

The user (of the control) creates the menu by adding menu items (on the server side), and specifies triggers which will make the menu pop (through javascript), but unlike the pop-up control it can have Multiple triggers.

My question is - what will be a good way to let the menu know it should pop?

I keep the IDs of the triggers in an array.

I tried adding an ''onclick ="menu.pop(x,y)" '' on every trigger, but that''s a bad idea because the "onclick" may already have some code in it (like "return false;" in some cases).

I saw that obout''s menu doesn''t add an "onclick" event, but couldn''t figure what exactly they did...

any suggestions?

Thanks in advanced,

Oren

推荐答案

他们可能已经添加了onclick事件,但他们可能没有内联完成.您还可以通过导航DOM并将事件处理程序添加到事件中,使用javascript动态添加onclick处理程序.例如:
They may have added an onclick event, but they may not have done it inline. You can also add onclick handlers dynamically using javascript by navigating the DOM and adding the event handler to the event. For example:
function MyHandler(){
    alert("Hello");
}
var button = document.findElementById("someElement");
button.onclick = MyHandler;


如果他们这样做,则在查看HTML源代码时将看不到处理程序.

另外,您可以将现有事件处理程序与新的事件处理程序包装在一起,并创建一个调用两者的事件处理程序.您可以执行此操作,甚至无需知道onclick已经附加了哪些事件处理程序. 此页面显示了操作方式(一直滚动到页面底部).


If they do it that way, you will not see the handler when you view the HTML source.

Also, you can wrap the existing event handler with your new event handler and create one that calls both. You can do this without even knowing what event handlers are already attached to onclick. This page shows how (scroll all the way to the bottom of the page).


这篇关于在不使用"onclick"的情况下弹出上下文菜单.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆