【发布时间】:2016-12-24 12:57:34
【问题描述】:
我想做一个看起来像按钮的复选框:当它被选中时,按钮看起来被按下;未选中时,按钮看起来未按下。
当我使用引导程序时,我自然会想到使用data-toggle="buttons-checkbox"。但是验证复选框的状态似乎不是很实用。例如,.prop('checked') 在以下代码中似乎不起作用。
$('#input-checkbox').click(function () {
if ($("#input-checkbox").prop('checked')) {
alert("yes");
} else {
alert("no");
}
});
<head>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></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>
有人知道那里出了什么问题吗?
【问题讨论】:
标签: javascript twitter-bootstrap checkbox