2017-09-21 2 views
0

Je peux obtenir le basculement du bootstrap en utilisant le HTML, mais je ne peux pas le faire en utilisant la méthode API Javascript. Fondamentalement, le premier bouton à bascule fonctionne, mais le second écrit en utilisant la méthode de l'API apparaît juste comme une case à cocher. Appréciez votre aide à clarifier ce que je me manque dans mon code:bootstrap bascule à l'aide de javascript

<script src="https://code.jquery.com/jquery.min.js"></script> 
 
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet"> 
 
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script> 
 

 
<input type="checkbox" data-toggle="toggle" data-on="Enabled" data-off="Disabled"> 
 

 
<input type="checkbox" id="toggle-two"> 
 
<script> 
 
    $(function() { 
 
    $('#toggle-two').bootstrapToggle({ 
 
     on: 'Enabled', 
 
     off: 'Disabled' 
 
    }); 
 
    }) 
 
</script>

Merci!

Répondre

0

J'ai trouvé la réponse. La fonction() n'a pas été nécessaire d'avoir dans mon code:

<script src="https://code.jquery.com/jquery.min.js"></script> 
 
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script> 
 
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet"/> 
 

 
<input type="checkbox" id="toggle-two"> 
 
<script> 
 
    $('#toggle-two').bootstrapToggle({ 
 
     on: 'Enabled', 
 
     off: 'Disabled' 
 
    }); 
 
</script>