Bootstrap Popover中的点击问题和按钮警报

Issue on Click and Alert on Button in Bootstrap Popover

本文关键字:按钮 问题 Popover Bootstrap      更新时间:2023-09-26

你能看看这个演示吗,让我知道为什么

$(".onealert").on("click",function(){
    alert("You clicked on A");
});

不起作用?

这是我的代码:

<div class="the-box">
    <div class="pull-right btn-group btn-group-sm" id="downloadSelect">
        <button type="button" class="btn btn-default">1</button> 
        <button href="#" class="trigger btn btn-default">2</button> 
        <button type="button" class="btn btn-default">3</button>
    </div>
    <div class="head hide">Alphabet Select</div>
    <div class="content hide">
        <div class="form-group">
            <div class="btn-group btn-group-sm">
                <button type="button" id="1Download" class="btn btn-default onealert">A</button>
                <button type="button" id="2Download" class="btn btn-default">B</button>
                <button type="button" id="3Download" class="btn btn-default">C</button>
            </div>
        </div>
    </div>
</div>

我也没有收到任何错误消息!

感谢

这是因为Bootstrap为出现的小对话框构建了新的标记,只使用隐藏的标记作为模板,这意味着它是添加事件处理程序时不存在的动态内容,您需要一个委托的处理程序

$('.the-box').on("click", ".onealert", function(){
    alert("You clicked on A");
});

FIDDLE