簡體   English   中英

jQuery通知欄

[英]jQuery Notification Bar

我正在嘗試在結帳頁面(FoxyCart模板)上安裝Noty (一個jQuery Notification插件)。 我在結帳模板的部分中安裝了以下代碼:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

<script type="text/javascript" src="http://lavajavamaui.com/js/noty/jquery.noty.js"></script>

<script type="text/javascript" src="http://lavajavamaui.com/js/noty/layouts/top.js"></script>
<script type="text/javascript" src="http://lavajavamaui.com/js/noty/layouts/topLeft.js"></script>
<script type="text/javascript" src="http://lavajavamaui.com/js/noty/layouts/topRight.js"></script>
<!-- You can add more layouts if you want -->

<script type="text/javascript" src="http://lavajavamaui.com/js/noty/themes/default.js">
</script>
<script type="text/javascript">
var noty = noty({text: 'noty - a jquery notification library!'});
</script>

如果我理解正確,那么就需要完成所有操作才能使其正確顯示。 由於某種原因,通知不會彈出。 這條線有什么問題嗎?

<script type="text/javascript">
var noty = noty({text: 'noty - a jquery notification library!'});
</script>

這是應該安裝Noty 的頁面

您正在復制文檔中的錯誤。

var noty = noty({text: 'noty - a jquery notification library!'});

如果在全球范圍內運行,重新定義noty ,更換功能noty與結果noty功能。 理論上,第一個調用應該可以工作,但是隨后對noty任何調用都將失敗,因為它們試圖將對象作為函數進行調用。 我不確定第一個失敗的原因,但有可能是相關的。 嘗試更改將結果分配給的對象的名稱:

var notyObj = noty({text: 'noty - a jquery notification library!'});

那可能會解決它。

如果您不需要在創建通知后對其進行操作,則還可以直接調用它,而無需將結果分配給變量:

noty({text: 'noty - a jquery notification library!'});

更新資料

如果您在非全局上下文(例如jQuery的ready事件)中執行該語句,則由於變量提升 ,該語句將無法工作。 提升采用任何var語句並將其移至該語句的頂部。 該聲明:

    (function () {
        var noty = noty({text: 'noty - a jquery notification library!'});
    }());

變成:

    (function () {
        var noty; // inside this function noty now refers
                  // to a local variable set to "undefined"

        // JavaScript looks for local variables before it looks at globals,
        // so it will use the new local "noty" when it tries to execute the
        // right side of this line. This will fail because you
        // can't invoke undefined
        noty = noty({text: 'noty - a jquery notification library!'});
    }());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM