从Bootstrap Popover内部的元素中删除类

时间:2018-10-04 07:29:32

标签: javascript jquery twitter-bootstrap popover

我正在使用引导弹出窗口显示收件人列表的可用操作列表。 弹出窗口:

<ul class='list-unstyled recipients-popover'>
<li><a href='#' class='popover-item' onclick='openAddContactModal()'><i class='test'></i> &nbsp; Add contact</a></li>
<li><a href='#' class='popover-item'><i class='test'></i> &nbsp; Add contact list</a></li>
<li><a href='#' class='popover-item disabled' onclick='deleteContacts()'><i class='test'></i> &nbsp; Delete contacts</a></li>
<li><a href='#' class='popover-item' onclick='openAddGroupModal()'><i class='test'></i> &nbsp; Create new group</a></li>
<li><a href='#' class='popover-item disabled' onclick='openAddContactToGroupModal()'><i class='test'></i> &nbsp; Add contacts to group</a></li>
<li><a href='#' class='popover-item disabled'><i class='test'></i> &nbsp; Remove contacts from Group</a></li>
<li><a href='#' class='popover-item' onclick='openDeleteGroupModal()'><i class='test'></i> &nbsp; Delete Group</a></li>

以上操作是由以下HTML触发的:

<a class="btn btn-link text-white" tabindex="0" role="button" data-html="true" data-trigger="focus" data-container="body" data-toggle="popover" data-placement="auto" data-content=" @include('recipient.actions-popover') ">

然后的问题是,当我尝试在弹出窗口上运行javascript时,它不起作用。例如,如果我尝试运行:

$(document).on('change', '.checkable', function(e) {
    console.log("testing");
    $(".popover-item").removeClass('disabled');
});

虽然我确实看到了测试控制台日志,但是无法删除禁用的类。

任何人都可以帮助上述工作吗?

1 个答案:

答案 0 :(得分:0)

如果您只想在复选框更改时删除一个类,则效果很好:

$(".checkable").change(function() {
       $(".popover-item").removeClass('disabled');
});
.disabled{
  color:red
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class='list-unstyled recipients-popover'>
<li><a href='#' class='popover-item' onclick='openAddContactModal()'><i class='test'></i> &nbsp; Add contact</a></li>
<li><a href='#' class='popover-item'><i class='test'></i> &nbsp; Add contact list</a></li>
<li><a href='#' class='popover-item disabled' onclick='deleteContacts()'><i class='test'></i> &nbsp; Delete contacts</a></li>
<li><a href='#' class='popover-item' onclick='openAddGroupModal()'><i class='test'></i> &nbsp; Create new group</a></li>
<li><a href='#' class='popover-item disabled' onclick='openAddContactToGroupModal()'><i class='test'></i> &nbsp; Add contacts to group</a></li>
<li><a href='#' class='popover-item disabled'><i class='test'></i> &nbsp; Remove contacts from Group</a></li>
<li><a href='#' class='popover-item' onclick='openDeleteGroupModal()'><i class='test'></i> &nbsp; Delete Group</a></li>

<label>Checkable</label> <input type="checkbox" name="recipient[3]" class="checkable" contactid="3">