【问题标题】:Popover HTML content with button and input not rendering [duplicate]带有按钮和输入的弹出式 HTML 内容未呈现 [重复]
【发布时间】:2020-05-17 00:10:05
【问题描述】:

我正在尝试向弹出框添加按钮,但它似乎没有呈现。

是像我一样做还是有更好的方法。

$('#myinput').popover({
    trigger   : "focus",
    container : 'body',
    placement : "bottom",
    html      : true,
    title     : "Choosy Popover",
    content   : `<input></input> Excellent <br><button type="submit">Why no display</button>`
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

<input id="myinput" />

【问题讨论】:

标签: javascript html bootstrap-4


【解决方案1】:

只需添加sanitize: false

$('#myinput').popover({
    trigger   : "focus",
    placement : "bottom",
    html      : true,
    title     : "Choosy Popover",
    content   : `<input></input> Excellent <br><button type="submit">Why no display</button>`,
    sanitize  : false, // here it is
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

<input id="myinput" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    • 2016-05-14
    • 1970-01-01
    • 2018-05-22
    • 2021-06-28
    • 2023-01-11
    相关资源
    最近更新 更多