Disable bootstrap switch after onswitchchange

I am new to coding with bootstrap and jquery. how can I disable the bootloader in the "onswitchchange" option

Here is my javascript / jquery code:

$("input[type=checkbox]").bootstrapSwitch({
    size:"mini",
    onSwitchChange:function(event, state) {
      this.disabled = true; //checkbox change into disabled
    }
  });

i also tried changing this.disabled = trueto $(this).setDisabled(true);and of course, he returned an error. I just want to know how to call a method setDisableinside a method onswitchchange. if that cannot be so. is there any other way to disconnect the switch after changing / click it?

+4
source share
1 answer

UPDATE: When using the Bootstrap switch, you can use one of two functions:

$(this).bootstrapSwitch("toggleDisabled"); // toggles whether `this` is disabled

$(this).bootstrapSwitch("disabled",true); // just disables the `this` element

, onSwitchChange bootstrapSwitch("disabled", true):

onSwitchChange:function(event, state) {
  $(this).bootstrapSwitch('disabled', true);
}

"", , - , .


- , jQuery

disabled, disabled.

, true, disabled.

( /) disabled=disabled.


jQuery, attr() ( - , - ):

onSwitchChange:function(event, state) {
  $(this).attr('disabled', 'disabled'); // set the element disabled attribute
}

.. , , form.


POSTed , readonly readonly:

onSwitchChange:function(event, state) {
  $(this).attr('readonly', 'readonly'); //checkbox is readonly, but still POSTed 
}

, disabled readonly: fooobar.com/questions/29073/...


. / checkbox. , .closest().

, :

  • div - div.
  • .some-class - , "some-class"
  • #someId id - id "someId"

closest, ( )

:

  // set the checkbox closest element with "bootstrapSwitch" class, to disabled
  $(this).closest('.bootstrapSwitch').attr('disabled', 'disabled');

, !:)

+3

Source: https://habr.com/ru/post/1652697/


All Articles