如何从 Javascript 执行 YUI 函数?
我如何从 javascript 调用包装在 YUI().use 内的 YUI 函数?
例子 下面是一个 YUI 函数“runShowAnim”,它执行 animShow.run();对于动画效果...
var runShowAnim = function(e) {
animShow.run();
};
我希望当我验证 javascript 函数中的某些内容时发生这种效果。我尝试如下调用它。但这似乎不起作用。
function notifyUser(message) {
document.getElementById("msgArea").innerHTML = message;
runShowAnim();
}
How can i call a YUI function that is wrapped inside a YUI().use from javascript?
example
Below is a YUI function "runShowAnim" which executes animShow.run(); for an animation effect...
var runShowAnim = function(e) {
animShow.run();
};
I want this effect to happen when i validate something in a javascript function. I tried to call it as below. But it doesn't seem to work.
function notifyUser(message) {
document.getElementById("msgArea").innerHTML = message;
runShowAnim();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我通过将 YUI 函数完全夹在一个函数中并调用该函数来实现这一点。
现在我可以调用 runShowAnim 而不会出现任何问题,如下面的示例函数所示。
I achieved this by sandwiching the YUI function completely inside a function and calling that function..
now i can call runShowAnim without any problem like in the below sample function..
如果要调用函数,则必须在函数名称后添加
()
后缀,并在函数名称之间包含 0 个或多个以逗号分隔的参数。如果该函数没有全局作用域(如果它是在传递给
use()
的函数内部声明的,则您的函数将具有全局作用域)并且没有以某种方式传递到外部,那么您只能从相同的位置执行此操作范围。If you want to call a function, you have to suffix the function name with
()
and include 0 or more comma separated arguments between them.If the function doesn't have global scope (as yours will have if it is declared inside a function passed to
use()
) and not passed outside in some way then you can only do this from the same scope.我认为你漏掉了括号。
I think you're missing the parentheses.
YUI.thefunction()?
我认为你也需要用命名空间来调用它,
类似于
YUI.thefunction()?
I think you need to call it with namespace too
something similar to
如果要从闭包外部调用已在闭包内部定义的函数(作为最后一个参数传递给 YUI.use 的函数),则需要全局公开该函数。
要么在闭包外部定义一个全局变量并将您的函数分配给它,要么将您的函数分配给窗口对象,
即
If you want to call a function that has been defined inside the closure (the function passed as the last parameter to YUI.use) from outside it, you need to expose the function globally.
Either define a global variable outside the closure and assign your function to it, or assign your function to the window object
i.e.