点击事件不起作用但mousedown确实如此

时间:2015-02-10 09:14:33

标签: jquery html

我正面临一个jquery问题。我的点击事件不起作用,但是mousedown没有      这工作

$(document).on('mousedown', '.penEdit', function () {
    $(this).parent().addClass('hOpen');
});

这不起作用

$(document).on('click', '.penEdit', function () {
    $(this).parent().addClass('hOpen');
});

我通过ajax加载html。

任何建议..

由于

3 个答案:

答案 0 :(得分:0)

对我来说它运作正常看看这个小提琴: http://jsfiddle.net/hLtzL6tv/

$(document).on('click', '.penEdit', function () {
    $('.check').parent().addClass('hOpen');
});

$(document).on('mousedown', '.penEdit1', function () {
    $('.checkMouseDown').parent().addClass('hOpen');
});

答案 1 :(得分:-2)

试着看看这是否有效:

$( ".penEdit" ).click(function() {
    alert( "Handler for .click() called." );
    console.log("I have clicked on penEdit :D");
});

如果浏览器中只有例外,或者Rory已经说过。尝试在所有浏览器中查看您是否处理异常。

答案 2 :(得分:-2)

您的代码没有错,也许您只是混淆了您添加的课程。

尝试在应该运行的点击事件中添加不同的类。

相关问题