gpt4 book ai didi

jquery - 单击按钮/下拉菜单时删除特定类

转载 作者:行者123 更新时间:2023-12-01 07:09:30 24 4
gpt4 key购买 nike

我想删除特定的类(“帮助文本”)。当用户单击按钮时,特定类将被删除。

这是我的代码

<div class="dropdown dropdown-lg">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<img src="img/find-match.png"/>
<span class="help-text">Click Here</span>
</button>
</div>

<script>
jQuery(document).click(function (e) {
if (!jQuery(e.target).hasClass('dropdown-lg')) {
jQuery('.dropdown-lg').removeClass('help-text');
}
});
</script>

请告诉我任何解决方案。

最佳答案

带有 help-textspan 位于按钮内部。所以你可以使用,

$(e.target).find('.help-text').removeClass('help-text')

$('.help-text',e.target).removeClass('help-text')

另外,我建议不要处理文档上的点击,,

$('button.dropdown-toggle').click(...

<强> Fiddle

$('button.dropdown-toggle').click(function(){
$(this).find('.help-text').toggleClass('help-text')
});

关于jquery - 单击按钮/下拉菜单时删除特定类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30931184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com