【发布时间】:2014-06-16 12:25:06
【问题描述】:
我希望仅在第一次单击按钮事件时更改按钮的图标类,这也将 ajax .put 一个字段到 db..
<div class="btn-group check-btns checkIt">
<button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-unchecked"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">List Item 1</a></li>
</ul>
</div>
首先测试了这个简单的 on.click (http://jsfiddle.net/57268/1/),但认为 Bootstrap 的内置下拉 .open 类切换可能会阻止这种情况..
$(document).ready(function () {
$(function () {
$('.checkIt').on('click', function () {
但是将其更改为收听正在显示的下拉菜单尚未起作用http://jsfiddle.net/57268/:
$(document).ready(function () {
$(function () {
$('.btn-group.check-btns.checkIt').on('show.bs.dropdown', function () {
console.log('checkIt clicked');
var $this = $(this);
var $that = $(this).children('.check-btns').children('.btn').find('.glyphicon')
if ($that.hasClass('.glyphicon-unchecked')) {
$that.removeClass('.glyphicon-unchecked').addClass('.glyphicon-check');
console.log('now checked icon');
$this.removeClass('.checkIt').addClass('.checkedIt');
console.log('now checkedIt class');
alert('checked and checkedIt .. now an ajax .put call');
}
})
});
});
【问题讨论】:
标签: javascript jquery html css twitter-bootstrap