Jquery-双击时遇到问题,因为类中发生了更改
Jquery - Getting trouble on double click because change in class
我有一个按钮。onclick
我正在更改该按钮的类,但当我双击它的更改类时。我的所有功能depend on current class
如何禁用双击或在第一次单击时完成请求。
function data() {
lastScrollTop = 0;
document.getElementById("expand-dataset-btn").disabled = false;
var id = event.target.id
var allChildern = null
if(!$(".id_"+event.target.id).hasClass('minus-symbol')){
$(".id_"+event.target.id).removeClass('plus-symbol').addClass('minus-symbol')
$.ajax({
},
success : function(result) {
}
});
}else{
$(".id_"+event.target.id).addClass('plus-symbol').removeClass('minus-symbol')
$.ajax({
},
success : function(result) {
}
});
}
}
从控制器调用功能,如下方
htmlDataId += "<a onclick='"data()'" title='View' id="+row[primaryField]+">
您需要的是"throttle"函数或"debounce"函数。
Throttling是一种方法,我们可以通过它来限制函数在给定时间段内被调用的次数。例如,我们可能有一个每秒调用不超过5次的方法。
你可以使用下划线官方网站
或
您可以使用以下代码:
/*trigger specific eventhandler when the event is idle for specific time*/
function debounce(fn, delay, self) {
var timer = null;
return function () {
var context = self ? self : this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
}, delay);
};
}
//use in the following way
$input.on('click',debounce(clickCallback,250));
如果第二次"点击"事件在250ms内触发,则会忽略
您应该等待ajax完成
function data() {
lastScrollTop = 0;
document.getElementById("expand-dataset-btn").disabled = false;
var id = event.target.id;
var allChildern = null;
if($(".id_"+ id).hasClass("disable"))
{
event.preventDefault();
}
if(!$(".id_"+ id).hasClass('minus-symbol')){
//make control disable
$(".id_"+ id).addClass('disabled');
$.ajax({
},
success : function(result) {
//change here after success
$(".id_"+ id).removeClass('plus-symbol').addClass('minus-symbol');
//remove control disable
$(".id_"+ id).removeClass('disabled');
});
}else{
//make control disable
$(".id_"+ id).attr('disabled', true);
$.ajax({
},
success : function(result) {
//change here after success
$(".id_"+ id).addClass('plus-symbol').removeClass('minus-symbol');
//remove control disable
$(".id_"+ id).attr('disabled', false);
}
});
}
}
相关文章:
- 为什么属性存在于对象实例上,即使其原型发生了更改
- Javascript函数 - 通过引用复制,但这里发生了什么
- 套接字发生了什么's在'断开连接'事件(服务器端)
- 这段代码中发生了什么
- Wamp没有识别出我的代码发生了更改
- 如何检查输入框值在使用淘汰之前是否发生了更改
- 通过它访问HTML元素's id DIRECTLY-这里发生了什么
- window.opener引用在Java 1.7.0_04-b20中从Applet重定向期间发生了更改,但在1.7.0_
- 如何知道JS对象属性的值在哪一行发生了更改
- 查找表单的哪些特定部分在输入时发生了更改
- JavaScript's数组过滤器函数在没有分配函数的情况下使用-这里发生了什么
- 起重行为在铬 48 和 49 之间发生了变化
- 这个JavaScript函数中发生了什么
- 我的输入字段听到除回车之外的每个“键下”事件.我有一个日期选择器,不确定发生了什么
- isPrototypeOf 说不,但实例说是——发生了什么
- 找出 Vue.js 深度自定义指令中哪个属性发生了变化
- 十分钟内的 Javascript:此示例代码中发生了什么说明惰性范围
- 键控后 AJAX 发生了一些奇怪的事情
- 发送到前端后,mysql 列中的日期发生了变化
- Jquery-双击时遇到问题,因为类中发生了更改