单击第二个按钮时如何使第一个按钮不活动

时间:2017-04-20 05:08:52

标签: jquery

$("#editText,#edit-formula").click(function(){
      if($(this).hasClass("active")){ 
       $(this).siblings("button").removeClass("active");
    }
 });

3 个答案:

答案 0 :(得分:0)

尝试使用:

$("button.active").removeClass("active");

答案 1 :(得分:0)

在单链方法中使用app.service('MyService', function($http) { console.log("Inside Service "); var finalAccountBalance = []; this.myFunc = function (x) { return x.toString(16); } this.calculateAccountBook = function (x,y) { console.log("Inside Service :: Inside calculateAccountBook"); var calculated = []; var payments =[]; //console.log(JSON.stringify(x)); $http.get('/totalpayments/search/findByHoaId_hoaId?hoaId='+y). then(function (response) { if (response.data._embedded != undefined) { payments = response.data._embedded.currentPaymentses; } else { payments = []; } angular.forEach(payments, function (value, key) { var obj={}; obj = { "processDate" : value.processDate, "description" : value.paymentTypeId.paymentTypeName+" - "+value.documentNum, "currentCharge" : "", "currentPayment" : value.amount, "accountBalance" : value.transactionBalance }; calculated.push(obj); }); angular.forEach(x, function (value, key) { var obj={}; obj = { "processDate" : value.assessmentDate, "description" : value.assessmentRuleType.name, "currentCharge" : value.amount, "currentPayment" : "", "accountBalance" : value.transactionBalance }; calculated.push(obj); }); calculated = sortByKey(calculated,'processDate'); finalAccountBalance = calculateAccountBalance(calculated); console.log("Final Calculated "+JSON.stringify(finalAccountBalance)); }); console.log("Final Balance "+JSON.stringify(finalAccountBalance)); return finalAccountBalance; }; function sortByKey(array, key) { return array.sort(function(a, b) { var x = a[key]; var y = b[key]; return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }); }; function calculateAccountBalance (cc) { var accountBalanceArr = []; angular.forEach(cc, function (value, key) { var obj={}; var lastObj = accountBalanceArr.slice(-1)[0]; var lastCharge; var lastPay; var lastBal; var currentBal; if(lastObj != undefined){ console.log("Inside Last Object"); lastCharge = lastObj.currentCharge; lastPay = lastObj.currentPayment; lastBal = lastObj.accountBalance ? lastObj.accountBalance : 0; console.log("Last Charge : "+lastCharge+" Last Pay : "+lastPay+" Last Balance : "+lastBal); } currentBal = lastBal + value.currentCharge - value.currentPayment; console.log("Current Balance "+currentBal); obj = { "processDate" : value.processDate, "description" : value.description, "currentCharge" : value.currentCharge, "currentPayment" : value.currentPayment, "accountBalance" : currentBal }; accountBalanceArr.push(obj); }); return accountBalanceArr; }; }); addClass

&#13;
&#13;
siblings
&#13;
$("#editText,#edit-formula").on("click", function() {
    $(this).addClass("active").siblings().removeClass('active');
      
});
&#13;
.active {
  background: red;
}
&#13;
&#13;
&#13;

答案 2 :(得分:0)

仅举例说明

int i = 1
    $(document).ready(function(){
        $('button').click(function(){
            $(this).attr('disabled', true).siblings("button").attr('disabled', false);
        });
    });