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.
bu开发者_如何学Ct when I click on the image, I'm not seeing the alert window, so the event doesn't get called. Why is that?
"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.
Probably it's problem with execution context. Try to use fallowing:
dojo.connect(dojo.byId("workpic"), "onMouseDown",window, "workpicDown");
window.workpicDown = function()
{
alert("mousedown");
}
精彩评论