-2

好吧,在我的 HTML 页面中,我有 6 个按钮,其值为 1、2、3、4、5,第 6 个按钮的值为“禁用”。我想做的就是通过使用jQuery单击“禁用”按钮来禁用特定按钮。例如,如果我按下第 3 个按钮,然后立即单击禁用按钮,则应禁用按钮 3,如果我单击第 4 个按钮,然后立即单击禁用按钮,则应禁用第 4 个按钮。

提前谢谢。

4

2 回答 2

1

纽扣

<button class="btn">1</button>
<button class="btn">2</button>
<button class="btn">3</button>
<button class="btn">4</button>
<button class="btn">5</button>
<button class="btn">6</button>
<button class="dis">Disable</button>

还有一些 jQuery

$('.btn').on('click', function() {
    $(this).addClass('active').siblings('button').removeClass('active');
});

$('.dis').on('click', function() {
    $('.btn.active').prop('disabled', true);
});

和一个

小提琴

于 2013-07-16T07:01:36.643 回答
0

你可以试试这个

$('button').on('click',function(){
   // your code;
   $(this).prop('disabled',true);
});

HTML

<button class="mybutton">1</button>
<button class="mybutton">2</button>
<button class="mybutton">3</button>
<button class="mybutton">4</button>
<button class="mybutton">5</button>
<button class="disable">Disable</button>

脚本

$(function(){
    $('.mybutton').on('click',function(){
        $(this).addClass('disableMe');
    });
    $('.disable').on('click',function(){
        $('.disableMe').prop('disabled',true);
    });    
});

工作小提琴

于 2013-07-16T06:59:44.967 回答