2011-03-20 6 views
0
  <style type="text/css"> 
     #thebutton { width: 100px; background-color: #eee; text-align: center;  
       padding: 10px; cursor: pointer; }    
     #thebutton.activated { font-weight: bold;} 
     #thebutton.hovering  { color: Blue; } 

#thebox { background-color: #eee; position:relative; width: 300px; height: 200px; 
       padding: 10px; top: 5px; display: none;} 
     </style> 

    <script type="text/javascript"> 
    $(document).ready(function() 
    { 

    $("#thebutton").click(function() { 
     var currentValue ; 


    $.ajax({ 

     type:  "post", 
     url:  "checklikes", 

     //data:   "user="+name.val(), 
     success: function(msg) 
        { 
         $("#replies").html(msg) 
      .fadeIn("fast"); 
         currentValue=parseInt(msg)+1; 

         $("#test").html(currentValue) 
      .fadeIn("fast"); 
          var data1= $("#test").text(); 


       $.ajax({ 

     type:  "post", 
     url:  "checkupdate", 

     data:   "user="+data1, 
     success: function(msg) 
        { 
         $("#t").html(msg) 
      .fadeIn("fast"); 
          $("#thebutton").toggleClass("activated"); 
      $("#thebutton").hasClass("activated") ? $("#thebox").fadeIn(): 
       $("#thebox").fadeOut();     

      $(this).attr('disabled','disabled'); 

        } 




    }); 
        } 




    }); 
     }); 
     }); 
    <body> 
    <div id="thebutton">Click me!</div> 
    <div id="thebox" style="display:none;">Content goes here</div> 
    </body> 

버튼을 클릭 한 후 비활성화하고 싶지만 작동하지 않습니다. 당신이 그것을 어떻게하려고 ('장애인')이 ATTR를 설정할 때클릭 후 div id를 비활성화하십시오.

+0

당신이 질문을 잊어 버렸습니다. – BoltClock

+0

질문을 올렸습니다. 그래서, 이것이 대답인지 모른다 :

Click me!
CarneyCode

+0

와우, 다소 편집에 문제가 생겼다. 우리는?!?!? – simnom

답변

1

대신

$("#thebutton").click(function() { 

의 내가 예를 들어 발견 한 코드에서

$("#thebutton").one("click", function() { 
+0

예, 작동합니다. – Deep

+0

은 이벤트 처리기 만 제거하고 실제로는 단추를 "비활성화"하지는 않습니다. – Alnitak

0

몇 가지를 시도 id #button 대신 .button 클래스. 그리고 실제로 사용할 수 있습니까? : 자바 스크립트 내에서 구문?

하나의 방법은 콜백에서 here

0

의 장식이 변경됩니다 버튼을 비활성화 처리하기 위해 jQuery를 UI의 자체 내부 방법을 사용하기위한 작업 예제가있다.

$('#thebutton').click(function() { 
    $('#thebutton') 
      .toggleClass('activated') 
      .button('disable') 
      .button('refresh'); // sometimes necessary 
}); 
관련 문제