jQuery에서 버튼 비활성화

5230 단어 jquery
Disable button in jQuery
My page creates multiple buttons as id = 'rbutton_"+i+"' . 내 페이지에는 id = 'rbutton_"+i+"'와 같은 여러 개의 단추가 만들어져 있습니다.Below is my code: 다음은 내 코드입니다.


In Javascript Javascript
function disable(i){
    $("#rbutton'+i+'").attr("disabled","disabled");
}

But it doesn't disable my button when I click on it. 그러나 내가 그것을 눌렀을 때, 그것은 나의 단추를 사용하지 않을 것이다.
#1층
참조:https://stackoom.com/question/11S3i/jQuery에서 버튼 비활성화
#2층
Use.propinstead(and clean up your selector string): 사용으로 변경.prop(선택기 문자열 정리):
function disable(i){
    $("#rbutton_"+i).prop("disabled",true);
}

generated HTML:생성된 HTML:



But the "best practices"approach is to use JavaScript event binding andthis instead: 그러나 "최고의 실천"방법은 JavaScript 이벤트 귀속this과 상반되는 것을 사용합니다.
 $('.rbutton').on('click',function() { $(this).prop("disabled",true); }); 
   

http://jsfiddle.net/mblase75/2Nfu4/http://jsfiddle.net/mblase75/2Nfu4/
#3층
Try this code:이 코드 시험:HTML HTML


function 기능
function disable(i){
    $("#rbutton_"+i).attr("disabled","disabled");
}

Other solution with jquery에서 jquery를 사용하는 기타 솔루션
$('button').click(function(){ 
    $(this).attr("disabled","disabled");
});

DEMO DEMO
Other solution with pure javascript 기타 솔루션 및 JavaScript



function disable(i){
 document.getElementById("rbutton_"+i).setAttribute("disabled","disabled");
}

DEMO2 DEMO2


#4

Here's how you do it with ajax. ajax 。

$("#updatebtn").click(function () {
    $("#updatebtn").prop("disabled", true);
    urlToHandler = 'update.ashx';
            jsonData = data;
            $.ajax({
                url: urlToHandler,
                data: jsonData,
                dataType: 'json',
                type: 'POST',
                contentType: 'application/json',
                success: function (data) {
                    $("#lbl").html(data.response);
                    $("#updatebtn").prop("disabled", false);
                    //setAutocompleteData(data.response);
                },
                error: function (data, status, jqXHR) {
                    alert('There was an error.');
                    $("#updatebtn").prop("disabled", false);
                }
            }); // end $.ajax

#5

Simply it's work fine, in HTML: HTML :


In JQuery side put this function for disable button: JQuery , :

function disableButton() {
    $('.btn_CommitAll').prop("disabled", true);
}

For enable button:

function enableButton() {
    $('.btn_CommitAll').prop("disabled", false);
}

That's all.


#6

There are two things here, and the highest voted answer is technically correct as per the OPs question. , OP , 。

Briefly summarized as:

$("some sort of selector").prop("disabled", true | false);

However should you be using jQuery UI (I know the OP wasn't but some people arriving here might be) then while this will disable the buttons click event it wont make the button appear disabled as per the UI styling. , jQuery UI( OP , ) , UI 。

If you are using a jQuery UI styled button then it should be enabled / disabled via: jQuery UI , / :

$("some sort of selector").button("enable" | "disable");

http://api.jqueryui.com/button/#method-disable http://api.jqueryui.com/button/#method-disable

좋은 웹페이지 즐겨찾기