Jquery 为什么重新添加的点击事件没有触发?
我的html呈现如下:Jquery 为什么重新添加的点击事件没有触发?,jquery,html,Jquery,Html,我的html呈现如下: <td colspan="2" onclick="reportTypeClick(this);" class="menuItem oneTest">...</td> if按预期工作,而else则不能。也就是说,我没有收到任何脚本错误,但事件未能触发 有什么想法吗 看起来这与这个有关 您是否可以使用该函数,而不是通过attr函数添加事件 [编辑]并使用jquery函数解除绑定 问候 Max您应该删除onclick属性并使用jquery事件处理 if
<td colspan="2" onclick="reportTypeClick(this);" class="menuItem oneTest">...</td>
if
按预期工作,而else
则不能。也就是说,我没有收到任何脚本错误,但事件未能触发
有什么想法吗
看起来这与这个有关 您是否可以使用该函数,而不是通过
attr
函数添加事件
[编辑]并使用jquery函数解除绑定
问候
Max您应该删除
onclick
属性并使用jquery事件处理
if(...) {
$('.oneTest').removeClass('menuItem').addClass('menuItemDisabled')
.unbind('click');
} else {
$('.oneTest').removeClass('menuItemDisabled').addClass('menuItem').each(function(){
var _this=this;
$(this).bind('click', function(){ reportTypeClick(_this) ););
});
}
或者,您可以更改您的报告类型,单击功能
function reportTypeClick(element)
{
if ( $(element).is('.menuItemDisabled') ) return; // add this line as the first line ..
// the current body of the function should follow..
}
您使用的是什么版本的jQuery?您能发布一篇文章吗?如果可能,您最好删除内联事件处理程序并使用jQuery的。单击()
和。绑定()
功能,如@JMax所说。我想我也会遇到同样的问题。
function reportTypeClick(element)
{
if ( $(element).is('.menuItemDisabled') ) return; // add this line as the first line ..
// the current body of the function should follow..
}