【问题标题】:I'm unable to add button to a popover我无法将按钮添加到弹出框
【发布时间】:2023-03-06 09:49:01
【问题描述】:

我一直在尝试向弹出框添加一个按钮。我有一个通过 asp.net 生成的 div 网格。我的代码如下所示:

$(document).ready(function () {
    $('.hometable').popover({
        html: true,
        trigger: "manual",
        title: function () {
            return $('#popover-title').html();
        },
        content: function () {
            return $('popover-content').html();
        }
    });
    
    $('.hometable').mousedown(){
        $(this).popover("show");
    }
}
<div id="popover-title" class="hide popover_name" hidden>
        <b>Overzicht</b>
</div>
<div id="popover-content" class="hide popover_name" hidden>
    <div>            
        <button>Test</button>
    </div>
</div>

<table> 
    @for(int i = 0; i < 5; i++){
        <tr>
             @for(int j = 0; j < 5; j++){
                 <td class="hometable">
                     <div></div>
                 <td>
             }
        </tr>
    }
</table>

如果我用 Test 替换按钮,它会正常工作,但我无法让按钮包含在其中。有什么建议?提前致谢!

【问题讨论】:

    标签: javascript html jquery asp.net popover


    【解决方案1】:

    由于弹出窗口中包含默认的“清理”功能,我的按钮似乎在加载后立即被自动删除。我可以通过在我的弹出框初始化中添加“sanitize:false”选项来解决这个问题。我的代码现在看起来像这样:

    $('.hometable').popover({
            html: true,
            trigger: "manual",
            sanitize: false,
            title: function () {
                return $('#popover-title').html();
            },
            content: function () {
                return $('popover-content').html();
            }
        });
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2019-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多