2011-03-20 69 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> 

單擊該按鈕後,我想禁用它,但它不起作用。取而代之的禁用div id後單擊

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

+0

你忘了提問了。 – BoltClock 2011-03-20 09:12:37

+0

你有問題。所以,我不知道這是否是答案:

Click me!
CarneyCode 2011-03-20 09:14:44

+0

Woah,有些改變與編輯的問題有沒有我們?!?!? – simnom 2011-03-20 09:22:16

回答

1

嘗試,我發現了實例的代碼

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

是的,它的工作原理是, – Deep 2011-03-20 09:23:37

+0

請注意,這隻會刪除事件處理程序,它並不實際「禁用」按鈕 – Alnitak 2011-03-20 09:25:18

0

幾件事情,當你設置的ATTR(「禁用」)你想這樣做是爲了一個.button類而不是id #button。你真的可以使用? :JavaScript內的語法?

無論哪種方式,有正常工作的例子給你here

0

在回調使用jQuery UI自身的內部方法來處理禁用這將改變它的裝飾按鈕。

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