[英]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.