Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery click()只需单击一次_Jquery - Fatal编程技术网

jQuery click()只需单击一次

jQuery click()只需单击一次,jquery,Jquery,我想让这个按钮只能点击一次。如果有人单击它更多次,则该功能将不会执行。我该怎么做 $(“.btn_排名”)。单击(函数(e){ e、 预防默认值(); var name=localStorage.getItem('name'); var time=localStorage.getItem('timer_end'); $.ajax({ url:“php/file.php”, 方法:“张贴”, 数据:{ 姓名:姓名,, 时间:时间 } }) }); 使用one()附加事件处理程序: $(“.btn_

我想让这个按钮只能点击一次。如果有人单击它更多次,则该功能将不会执行。我该怎么做

$(“.btn_排名”)。单击(函数(e){
e、 预防默认值();
var name=localStorage.getItem('name');
var time=localStorage.getItem('timer_end');
$.ajax({
url:“php/file.php”,
方法:“张贴”,
数据:{
姓名:姓名,,
时间:时间
}
})
});
使用
one()
附加事件处理程序:

$(“.btn_排名”).one('click',函数(e){
e、 预防默认值();
var name=localStorage.getItem('name');
var time=localStorage.getItem('timer_end');
$.ajax({
url:“php/file.php”,
方法:“张贴”,
数据:{
姓名:姓名,,
时间:时间
}
});
});

除了Rory的答案,您还可以执行以下操作之一:

我无法从您的代码中分辨出您的标记是什么,但是如果您的
.btn\u ranking
元素是一个
标记,那么在单击功能中,您还可以向按钮添加一个
disabled
属性,这将防止再次单击该按钮。

您可以做的另一件事是向
指针事件的相同元素添加内联样式:none

所有这些解决方案都需要注意的一点是,只需刷新浏览器即可避免这些问题