Bootstrap switch Uncaught TypeError: Cannot read property ‘apply’ of undefined

<input type=”checkbox” name=”my-switch” checked>

js write the following code, otherwise the switch control will not come out

















<div class="make-switch" data-on-label="开" data-off-label="关" id="toggle-state-switch" data-on="success" data-off="warning">
    <input id ="toggle" type="checkbox"  checked="checked" class="toggle"  />

function changeState(stateValue){
            $('#toggle-state-switch').bootstrapSwitch('setState', true);
            $('#toggle-state-switch').bootstrapSwitch('setState', false);

Use the above method

$(‘#toggle-state-switch’).bootstrapSwitch(‘setState’, false); There is a problem

It should be used

$(‘#toggle-state-switch’).bootstrapSwitch(‘state’, true/false);

Another pit is to use the ID of the external div to set the state of the bootstrap switch, and there will be more nodes, as follows:

This is not the result we want, so it is wrong to set the value of external Div. The ID of the check box should be set as follows:

$(‘#toggle’).bootstrapSwitch(‘state’, false);

When assigning a value to the bootstrap switch, an error
uncaught type error: cannot read property 'apply' of undefined is prompted

        if (isUp==undefined || isUp == ''){
        } else{

The detailed error information is shown in the following figure:

I refer to this setting and use jQuery to get the value of bootstrap switch
it seems that there is a problem, so I check the source code. There is no setstate method at all. I should use the following method:

            $('#toggle').bootstrapSwitch('state', true);
            console.log("Status enabled or not 1:",stateValue);
            console.log("Status enabled or not 2:",stateValue);
            $('#toggle').bootstrapSwitch('state', false);

Similar Posts: