简体   繁体   English

为什么我的点击事件没有触发?

[英]Why is my click event not firing?

I have a form with a button. 我有一个带有按钮的表格。 When the button is clicked I want to run a jQuery code. 当单击按钮时,我要运行jQuery代码。 I have not been able to get it to work and am getting really frustrated. 我无法使其正常工作,并且感到非常沮丧。 First I thought my selector was not right. 首先,我认为我的选择器不正确。 So, I tried to test it by changing the click event to hover event. 因此,我尝试通过将click事件更改为hover事件来对其进行测试。 Hover event WORKED. 悬停事件有效。 Exactly the same button, exactly the same jQuery code. 完全相同的按钮,完全相同的jQuery代码。 The only difference is that I changed it to Hover. 唯一的区别是我将其更改为Hover。 Why is it not working on click? 为什么点击不起作用? Any ideas? 有任何想法吗? Code is here 代码在这里

this doesnt fire: 这不会触发:

$(document).ready(function(){
$("#marketFloorID .sellButton").click(function(){
alert('works');
})
})

this does fire: 确实会触发:

$(document).ready(function(){
$("#marketFloorID .sellButton").hover(function(){
alert('works');
}),
function(){
//code;    
})
})

Try this 尝试这个

using element's id: 使用元素的ID:

    $(function(){
        $('#yourID').on('click',function(){ //do something });
    });

using element's class: 使用元素的类:

    $(function(){
        $('.yourClass').on('click',function(){ //do something });
    });

I figured it out. 我想到了。 I had another click event for the same button defined in a different js file. 对于另一个js文件中定义的同一按钮,我还有另一个click事件。 As soon as I deleted that function it started to work. 删除该功能后,它便开始起作用。 Thanks all 谢谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM