HTML Javascript物理点击触发事件,但逻辑点击不触发';T

HTML Javascript物理点击触发事件,但逻辑点击不触发';T,javascript,html,events,triggers,onclick,Javascript,Html,Events,Triggers,Onclick,我有这个按钮: <button class="dijitStretch dijitButtonNode dijitButtonContents dijitButton jStopThreads dijitButton" dojoattachevent="onclick:_onButtonClick,onmouseenter:_onMouse,onmouseover:_onMouse,onmouseout:_onMouse,onmouseleave:_onMouse,onmousedown:

我有这个按钮:

<button class="dijitStretch dijitButtonNode dijitButtonContents dijitButton jStopThreads dijitButton" dojoattachevent="onclick:_onButtonClick,onmouseenter:_onMouse,onmouseover:_onMouse,onmouseout:_onMouse,onmouseleave:_onMouse,onmousedown:_onMouse" dojoattachpoint="focusNode,titleNode" type="button" wairole="button" waistate="labelledby-jStopThreads_label" role="button" aria-labelledby="jStopThreads_label" id="jStopThreads" tabindex="0" widgetid="jStopThreads" aria-valuenow="" aria-disabled="false" style="position: absolute; left: 76px; top: 528px; z-index: 3; width: 104px; height: 20px;"><span class="dijitInline " dojoattachpoint="iconNode"><span class="dijitToggleButtonIconChar">✓</span></span><span class="dijitButtonText" id="jStopThreads_label" dojoattachpoint="containerNode">


按钮点击是因为它聚焦,但是关联的事件没有被触发?这怎么可能呢?

这是因为jQuery只能触发通过jQuery添加的事件。 因此,如果您想通过jQuery这样添加事件:

$('.jStopThreads').click(function() {
  // the content of your function
});

稍后可以通过jQuery函数trigger()或click()调用它。看起来您正在使用库Dojo来附加click事件。在jQuery中执行此操作:

function clickHandler(e) {
    alert('clicked!');
}

$('.jStopThreads').on('click', clickHandler);

$('.jStopThreads').trigger("click");

阅读有关使用dojo触发事件的信息。可能会将Dojo添加到标记中,因为它是问题的根源!我只是想知道为什么按钮处理物理点击,但逻辑点击!您在代码中所做的是添加其他执行的click处理程序,但不会触发附加到按钮的事件。它没有通过jQuery注册click处理程序。然后您试图用jQuery触发点击。因此,实际上,在jQuery上下文中,您的按钮没有处理程序。另外,也许可以用感叹号放松一下,你听起来很生气和沮丧,这对我们帮助你没有帮助。所以,如果注册了jQuery click侦听器,jQuery只会触发“click”?如果我听起来很沮丧,很抱歉,但实际上,我已经陷入这一困境好几个小时了,无法解决它。谢谢。或者内联添加的事件
onclick=“doSomething”
按钮已经有onclick事件。当我点击它时,它会触发一个事件(继承自我讨厌的糟糕ide)。我需要实现的是用javascript/jquery而不是物理鼠标点击来触发该事件……正如benjarwar在下面所写的:您的事件没有添加到jquery上下文中,因此很遗憾,无法通过jquery触发它。请看大卫推荐的阅读材料。
$('.jStopThreads').click(function() {
  // the content of your function
});
function clickHandler(e) {
    alert('clicked!');
}

$('.jStopThreads').on('click', clickHandler);

$('.jStopThreads').trigger("click");