Home  >  Article  >  Web Front-end  >  How to set initial value for bootstrap-switch

How to set initial value for bootstrap-switch

angryTom
angryTomOriginal
2019-08-01 13:48:494518browse

How to set initial value for bootstrap-switch

bootstrapSwitch is a very beautiful switching control, and its introduction on the official website is also very detailed. Let’s quickly get started with bootstrapSwitch through several demos.

If you want to know more about bootstrap, you can click: bootstrap tutorial

First, quote the corresponding js and css files, put the checkbox into the div with class "switch", and then initialize

 $('#mySwitch input').bootstrapSwitch();

in js to use bootstrapSwitch.

Input has two attributes data-on-text and data-off-text, which are the text displayed when switching, respectively. Here they are set to YES and NO . The code is as follows:




    
    this is a bootstrap-switch test
    
    
    
    
    
 
    


 

How to set initial value for bootstrap-switchHow to set initial value for bootstrap-switch

##You can also use js to set these two attributes. After selecting the input element, use the method

bootstrapSwitch({attribute:value}) Modify attributes. The code is as follows:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>this is a bootstrap-switch test</title>
    <script src="jquery-2.2.4.js"></script>
    <script src="bootstrap.js"></script>
    <script src="bootstrap-switch.js"></script>
    <link rel="stylesheet" type="text/css" href="bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="bootstrap-switch.css"/>
    <script type="text/javascript">
        $(function(){
            $(&#39;#mySwitch input&#39;).bootstrapSwitch({
                onText:&#39;On&#39;,
                offText:&#39;Off&#39;
            });
        })
    </script>
</head>
<body>
<br>
<div  id="mySwitch">
    <input type="checkbox" checked  data-on-text="YES" data-off-text="NO"/>
</div>
</body>

How to set initial value for bootstrap-switchHow to set initial value for bootstrap-switch

The above is the detailed content of How to set initial value for bootstrap-switch. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn