简体   繁体   中英

if check box is checked hide checkbox

I have laravel blade where I am updating a DB value using checkbox. I want if a user check that checkbox it should be either hidden on click or disabled but nothing works. What mistake i am making? or i should try any other method?

 $(document).ready(function() { $(document).on('change', '.js-switch', function() { let received_amount = $(this).prop('checked') === true ? 1 : 0; if ($(this).prop('checked') == 0) { $(this).closest('tr').addClass('cancel'); } else { $(this).closest('tr').removeClass('cancel'); } let userId = $(this).data('id'); $.ajax({ type: "GET", dataType: "json", url: "url", data: { 'received_amount': received_amount, 'user_id': userId }, success: function(data) { console.log(data.message); } }); $(".red").show(); $(this).hide() }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <span>Received Subtotal</span> <input type="checkbox" data-id="1" name="equal_order" value="red" class="red"></label>

Solved this using the attribute "disabled".

$(document).ready(function() {
  $('#checkbox1').click(function() {
    $(this).attr("disabled", true);
  });
});

Codepen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM