最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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 pletely 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?

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 pletely 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?

Share Improve this question edited Mar 25, 2011 at 10:55 Cobra_Fast asked Mar 25, 2011 at 10:44 Cobra_FastCobra_Fast 16.1k8 gold badges63 silver badges105 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

"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");
}
发布评论

评论列表(0)

  1. 暂无评论