我想在元素上启用/禁用单击事件.我有以下代码......
HTML:
<a id="CP" style="cursor: pointer; text-decoration: underline;">Current Processes</a>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$(document).on("click", "#CP", function(event) {
$this = $(this);
$this.click(function() {
return false;
});
$this.html("Processing...").css({
"text-decoration": "none",
"cursor": "default"
});
$.ajax({
type: 'post',
url: 'abc.jsp',
success: function(process) {
//My code goes here...
$this.on("click"); // Here i want to bind or add handler which is fired previously.
}
});
});
Run Code Online (Sandbox Code Playgroud)
如果我理解得很好,你可以用以下方法做到这一点:
$this.html("Processing...").css({
"cursor": "wait",
"pointer-events": "none"
});
Run Code Online (Sandbox Code Playgroud)
在执行 AJAX 请求时添加一些类。完成后删除。如果链接有这个类,则什么都不做。
$(document).on("click", "#CP", function(event) {
event.preventDefault();
$a = $(this);
if($a.hasClass('disabled')) {
return false;
}
$a.html("Processing...").addClass('disabled');
$.ajax({
type: 'post',
url: 'abc.jsp',
success: function(process) {
$a.removeClass('disabled');
// restore inner HTML here
}
});
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
29516 次 |
最近记录: |