简体   繁体   English

只要在页面上单击任何内容,Bootstrap工具提示就会停止工作

[英]Bootstrap tooltips stop working whenever anything is clicked on the page

On my page, I initialize Bootstrap tooltips this way 在我的页面上,我以这种方式初始化Bootstrap工具提示

<script>
    $(document).ready(function () {
        $(function () {
            $('[data-toggle="tooltip"]').tooltip();
        });
    });
</script>

This question suggests that any time an event happens you have to reload tooltips. 这个问题表明,每当事件发生时,您都必须重新加载工具提示。 However, across various ajax page updating there are probably 50+ events to account for. 但是,在各种Ajax页面更新中,可能要考虑50多个事件。 (This site is using asp.net web forms and ajaxcontroltoolkit) (此站点使用asp.net Web表单和ajaxcontroltoolkit)

How can I universally reinitiate tooltips every time an event takes place? 每当事件发生时,如何通用地重新启动工具提示? -- or is there a simpler solution to solving this problem? -还是有更简单的解决方案来解决这个问题?

You need a javascript reference to Sys.WebForms.PageRequestManager 您需要对Sys.WebForms.PageRequestManager的JavaScript参考

Take a look at the beginRequest/endRequest events. 看一下beginRequest / endRequest事件。 Since asp.net ajax is replacing your html you'll need to rebind the bootstrap widgets after asp.net is finished with its ajax. 由于asp.net ajax会替换您的html,因此您需要在asp.net完成其ajax后重新绑定引导小部件。

Try this: 尝试这个:

<script>
var prm = Sys.WebForms.PageRequestManager.getInstance();
//func to rebind tooltip
function reBind () { $('[data-toggle="tooltip"]').tooltip(); }
$(document).ready(function () {
    $(function () {
        reBind();            
        prm.add_endRequest(reBind);
    });
});
</script>

Be warned some bootstrap widgets will break if they are bound twice, so use your discretion; 请注意,如果将某些引导小部件绑定两次,则它们会损坏,因此请谨慎使用; some elements might need to have their events monitored to see if they are bound more than once. 有些元素可能需要对其事件进行监视,以查看它们是否绑定了多个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM