Javascript jQuery通知栏
我正在尝试在签出页面(FoxyCart模板)上安装(jQuery通知插件)。我在签出模板的部分安装了以下代码:Javascript jQuery通知栏,javascript,jquery,html,notifications,Javascript,Jquery,Html,Notifications,我正在尝试在签出页面(FoxyCart模板)上安装(jQuery通知插件)。我在签出模板的部分安装了以下代码: <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/j
<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>
var noty=noty({text:'noty-jquery通知库!'});
如果我理解正确的话,这就是让它正确显示所需要做的一切。由于某种原因,通知没有弹出。这条线有什么问题吗
<script type="text/javascript">
var noty = noty({text: 'noty - a jquery notification library!'});
</script>
var noty=noty({text:'noty-jquery通知库!'});
这是应该安装Noty的。您正在复制文档中的一个bug。线路
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!'});
}());
不,那一行是正确的。那一页有很多错误。。和多个jquery版本。。你需要先解决这些问题,我只能控制一个jquery.min.js(1.7)文件。其他一切都来自托管支付提供商。删除了我的jQuery include行,仍然没有显示。您还可以将调用包装在一个
$(document).ready()
中,该调用将在匿名函数中移动变量(这是作者在js/script.js
中所做的操作)。@pete由于变量的提升,实际上无法工作,我将扩展我的答案来涵盖这一点。变量提升与此无关。我说的是将var notyObj=
语句放入$(document.ready()
的匿名函数中。通过这样做,notyObj
变量被声明(并作用于)匿名函数,因此它不在全局作用域上声明。啊,我想你的意思是将var noty=noty()
移动到ready
。使用不同的变量名在本地上下文中仍然有效,就像在全局上下文中一样。我同意,最好不要把全球范围搞得乱七八糟@皮特