disable button when first click in jquery

假如想象 提交于 2019-12-08 08:34:57

问题


I want to disable button when user first click it so it must not save multiple record if a user have a slow connection. Im using asp.net mvc2


回答1:


$('#buttonId').click(function() {
    $(this).attr('disabled', 'disabled');
});

Of course you have to adjust the selector.




回答2:


You can use jQuery's one(). With this, the event handler is executed only once. Inside the event handler you can disable or change the style.

Example from jQuery site:

$('#foo').one('click', function() {
  alert('This will be displayed only once.');
});


来源:https://stackoverflow.com/questions/3573849/disable-button-when-first-click-in-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!