Javascript Bootstrap toggle kullanımı

Yazar: | 12 Haziran 2018

Bootstrap toggle kullanarak javascript ile codeigniter projesinde işlem yapabilirsiniz. Bunun için bootsratp toggle  sitesinden detayları inceleyebilirsiniz.

<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 id="toggle-event" type="checkbox" data-toggle="toggle">
<div id="console-event"></div>
<script>
  $(function() {
    $('#toggle-event').change(function() {
      $('#console-event').html('Toggle: ' + $(this).prop('checked'))
    })
  })
</script>

daha sonra kendi projenize göre düzenleyin.

 <script type="text/javascript">
      $(document).ready(function() {

        $(function() {
          $('#toggle-event').change(function() {
            var isActive = ($(this).prop('checked'));

            var base_url = $(".base_url").text();
           
           var id = $(this).attr("dataID");

            alert(id);
            $.post(base_url + "controllername/functionname",{id:id,isActive:true}, function(response){

              alert(response);
            })
          })
        })


      });
    </script>

Data toggle’dan kayıt id almak için toggle içine dataID parametresi tanımlıyoruz.

  <input id="toggle-event" type="checkbox" data-toggle="toggle" id="toggle-event"  dataID="<?php echo $pic->id; ?>">

 

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir