jquery点击功能不起作用

问题描述:

我想给我的按钮使用jquery click函数的一些功能。但是当我运行代码的时候,函数根本不会被调用。jquery点击功能不起作用

我的代码是:

<script type="text/javascript"> 
$(function() { 
    $("#min").click(function(e){ 
     $("#listFriends").css('display','none'); 
     $("#friendsO").show(); 
    }); 
</script> 

而且

<button id="min">[-]</button> 

请任何人告诉我,我在此代码做什么错误.....谢谢..........

+0

当您绑定事件时,该按钮是否存在? – 2013-02-23 21:15:48

+0

@ Jean-Philippe Leclerc yes否则我如何点击按钮 – james 2013-02-23 21:19:14

+0

您可以将按钮加载到ajax中,或者添加到dom中后将事件绑定到元素。 – 2013-02-23 21:19:53

对于关闭文档就绪处理程序,您缺少});

$(function() { 
    $("#min").click(function(e){ 
     console.log('test'); 
     $("#listFriends").hide(); 
     $("#friendsO").show(); 
    }); 
}); // <---- 

如果您生成动态元素,你应该委托的情况下,从元件的静态父母一方或document对象:

$(document).on('click', "#min", function(e){ 
     console.log('test'); 
     $("#listFriends").hide(); 
     $("#friendsO").show(); 
}); 
+0

对不起,我再次纠正这不工作.. – james 2013-02-23 21:09:03

+0

@james你看到控制台上的任何错误?你有没有包含jQuery库? – undefined 2013-02-23 21:11:21

+0

没有错误没有任何东西......我用jQuery添加这个按钮..这是什么原因导致这个问题... – james 2013-02-23 21:15:11

在Firefox中安装萤火虫并启用调试,看看here

+0

我有萤火虫......当我蹲在按钮上时它不会显示任何东西... – james 2013-02-23 21:17:33