【问题标题】:Custom Notifications using bootstrap使用引导程序的自定义通知
【发布时间】:2015-11-02 15:17:31
【问题描述】:

我正在使用引导通知向我的最终用户显示信息性消息。 http://goodybag.github.io/bootstrap-notify/

我有一个DIV

<div class="notifications bottom-right"></div>

理论上,库应该处理 JS 我已确保库已加载,但仍然没有显示通知窗口我不知道为什么我希望在页面加载时发生这种情况,所以如果有积分待定。

我将如何调整脚本标签以通过PHP 实现这一目标?

<script>
    $('.bottom-right').notify({
        message: { text: 'Aw yeah, It works!' }
    }).show(); // for the ones that aren't closable and don't fade out   there is a .hide() function.
</script>

编辑以在 Header 中显示文件我使用了 wp enque obv

<script type='text/javascript' src='http://fundrasing.davidbuckleyni.co.uk/wp-content/themes/gogreensoccer5/js/bootstrap-notify.js?ver=201202012'></script>
<link rel='stylesheet' id='notifcations-css1-css'  href='http://fundrasing.davidbuckleyni.co.uk/wp-content/themes/gogreensoccer5/css/bootstrap-notify.css?ver=1.0' type='text/css' media='all' />
<link rel='stylesheet' id='notifcations-css2-css'  href='http://fundrasing.davidbuckleyni.co.uk/wp-content/themes/gogreensoccer5/css/styles/alert-blackgloss.css?ver=1.0' type='text/css' media='all' />
<link rel='stylesheet' id='notifcations-css3-css'  href='http://fundrasing.davidbuckleyni.co.uk/wp-content/themes/gogreensoccer5/css/styles/alert-bangtidy.css?ver=1.0' type='text/css' media='all' />

【问题讨论】:

    标签: php jquery css twitter-bootstrap


    【解决方案1】:

    工作示例:https://jsfiddle.net/mwatz122/1k3s7m80/

    确保包含所有必要的库(CSS 和 JS)。在我的 JSFiddle 示例中,我包含了来自 CDN 的 bootstrap-notify.min.cssalert-bangtidy.min.cssalert-blackgloss.min.cssbootstrap-notify.min.js

    如果您希望在页面加载时显示通知,您应该在 $(document).ready 块中包含 JavaScript 代码,如图所示。

    <div class='notifications bottom-right'></div>
    
    $(document).ready(function () {
        $('.bottom-right').notify({
            message: {
                text: 'Aw yeah, It works!'
            }
        }).show();
    });
    

    编辑:

    您的网站在页面加载时抛出错误:

    Uncaught TypeError: $(...).notify is not a function
    

    这意味着未检测到bootstrap-notify.min.js 源文件。我会先尝试引用 CDN,以确保您可以使其正常工作。您应该在标题中的bootstrap-notify.min.js 文件之前包含jQueryBootstrap。您可以将其用作您的 CDN 链接https://cdnjs.cloudflare.com/ajax/libs/bootstrap-notify/0.2.0/js/bootstrap-notify.min.js

    【讨论】:

    • @Mathew 我在这里,但我似乎看不到通知工作fundrasing.davidbuckleyni.co.uk
    • 你同时包含了 jQuery 和 Bootstrap,对吧?
    • 是的,你可以在我的视图源中看到它们,我应该将 div 放在 wordpress 页脚中,以防万一出现问题但仍然没有通知:-(
    • 是的,但我的网站上确实有一个背景图片,你想知道它是否可以隐藏它:-(
    • 我复制并粘贴了您发布的内容,以防错字问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    相关资源
    最近更新 更多