Dojo.Connect Event doesn't get called - why?

别来无恙 提交于 2019-12-12 12:21:10

问题


I am trying to connect an onMouseDown event to an image with dojo.connect like:

dojo.connect(dojo.byId("workpic"), "onMouseDown", workpicDown);

function workpicDown()
{
    alert("mousedown");
}

Similar code a few lines later, where I'm connecting onMouse* events to dojo.body does work completely properly.

but when I click on the image, I'm not seeing the alert window, so the event doesn't get called. Why is that?


回答1:


"onMouseDown" should be all lower case when used with DOM events as opposed to Widget events. Try:

dojo.connect(dojo.byId("workpic"), "onmousedown", workpicDown);

From the documentation:

A note about the event names: Event names now are lower case, except in special cases (e.g., some Mozilla DOM events). Dojo will add "on" to your event name if you leave it off (e.g., 'click' and 'onclick' are the same thing to dojo). This differs from Widget Events in the sense Dijit uses mixedCase event names, to avoid potential conflicts.




回答2:


Probably it's problem with execution context. Try to use fallowing:

dojo.connect(dojo.byId("workpic"), "onMouseDown",window, "workpicDown");

window.workpicDown = function()
{
    alert("mousedown");
}


来源:https://stackoverflow.com/questions/5431381/dojo-connect-event-doesnt-get-called-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!