【问题标题】:Bootstrap ajax call from popover contents从弹出内容中引导 ajax 调用
【发布时间】:2016-05-30 08:49:59
【问题描述】:

我必须从#id 的内容中调用ajax 或任何类型的发布请求。 而#id 是这样隐藏的:

<div id="mycontents" style="display: none;">
    <div class="btn-group" role="group">
        <button type="button" class="btn btn-danger btn-sm" id="click_id">Click</button>
    </div>
</div>

如何从 #mycontents 触发 ajax 调用?

$('#id').popover({
    trigger : 'hover',
    delay : {
        show : 1,
        hide : 10000
    },
    html : true,
    content : function() {
        return $('#mycontents').html();
    }
})

问题是某些浏览器会忽略 display: none 元素,因此我无法从中触发任何事件。

例如,当我点击按钮时,我想触发这个:

$('#click_id').click(function(e) {
    $.ajax({
        type: "GET",
        url: "/click_id",
        async: true,
        dataType: "html",
        success: function(data) {
            // Do stuff
        }
    });
});

谢谢!

【问题讨论】:

  • 请写下您的明确需求,以便stackoverflow能给您一个合适的解决方案
  • 添加了更多描述。谢谢。 display: none 只是禁用一切...
  • 什么意思“我如何从这个#mycontents 触发ajax 调用?” 你想什么时候触发这个请求..?你想达到什么目的..?
  • 您可以使用$('#click_id:visible').click($('#click_id:hidden').click(。 - 根据您的要求。
  • @cvxv31431asdas - 你对此有进一步了解吗?很想看到解决方案!

标签: javascript jquery html ajax twitter-bootstrap


【解决方案1】:

试试这个:

$('#id').popover({
    trigger : 'hover',
    delay : {
        show : 1,
        hide : 10000
    },
    html : true,
    content : function() {
        var myhtml = $('#mycontents').html();
        $('#mycontents', myhtml).removeAttr('style');
        return myhtml
    }
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-12
    • 1970-01-01
    • 2012-04-12
    • 2017-04-28
    • 2013-12-05
    • 2017-09-14
    • 2020-07-27
    • 2021-12-22
    相关资源
    最近更新 更多