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

How to set initial value for bootstrap-switch

angryTom
Release: 2020-05-15 09:22:36
Original
4639 people have browsed it

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();
Copy after login

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
    
    
    
    
    
 
    

Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template