<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>
点击按钮后我想禁用它,但它无效。
答案 0 :(得分:1)
而不是
$("#thebutton").click(function () {
试
$("#thebutton").one("click", function () {
答案 1 :(得分:0)
我发现代码中很少有东西,例如当您设置attr('disabled')时,您试图将其设置为.button而不是id #button。你真的可以用吗? :javascript中的语法?
无论哪种方式,都有适合你的工作示例here
答案 2 :(得分:0)
在你的回调中使用jQuery UI自己的内部方法来处理禁用按钮的方法,这将改变它的装饰。
$('#thebutton').click(function () {
$('#thebutton')
.toggleClass('activated')
.button('disable')
.button('refresh'); // sometimes necessary
});