vendredi 23 décembre 2016

Check the state of buttons-checkbox

I want to make a checkbox that looks like a button: when it is checked, the button looks pressed; when it is unchecked, the button looks unpressed.

As I use bootstrap, naturally I think of using data-toggle="buttons-checkbox". But It does not seem very practical to verify the state of the checkbox. For example, .prop('checked') does not seem to work in the following code.

  $('#input-checkbox').click(function () {
    if ($("#input-checkbox").prop('checked')) {
      alert("yes");
    } else {
      alert("no");
    }
  });
<head>
  <script src="http://ift.tt/1sNUv3Z"></script>
  <link href="http://ift.tt/1jAc5cP" rel="stylesheet" type="text/css" />
  <script src="http://ift.tt/1jAc4pg"></script>
</head>
<body>
  <div class="btn-group" data-toggle="buttons-checkbox">
    <button type="button" class="btn btn-default active" id="input-checkbox">INPUT</button>
  </div>
</body>

Does anyone know what's wrong there?




Aucun commentaire:

Enregistrer un commentaire