Javascript Onready函数调用Namespace函数
我正在删除 Rails/views/show.html.erb 中使用的 Javascript 中的全局变量
我使用的 javascript 是
var App = {};
App.UserSnapShot = function () {
var _body, _detailEl, _selectedLinkEl;
var _init = function () {
_body = $$("body")[0];
$$(".user-link").each(function (el) {
el.observe("mouseover", function (event) {
_selectedLinkEl = el;
_detailEl = event.element().next();
_detailEl.show();
_body.observe("mouseover", _bodyMouseOverFunction);
});
});
};
var _bodyMouseOverFunction = function (event) {
if (event.element() != _selectedLinkEl &&
event.element() != _detailEl &&
!event.element().ancestors().include(_detailEl)) {
_detailEl.hide();
_body.stopObserving("mouseover", _bodyMouseOverFunction);
}
};
return {
init: function () {
_init();
}
};
}();
我需要调用我的函数 App.UserSnapShot.init();通过相同的 onready 函数..,这样才能让它发挥作用.. 我如何在这里添加 onReady 函数。
请给一些建议
i am removing the global variables in the Javascript that is used in my Rails/views/show.html.erb
The javascript that i am using is
var App = {};
App.UserSnapShot = function () {
var _body, _detailEl, _selectedLinkEl;
var _init = function () {
_body = $("body")[0];
$(".user-link").each(function (el) {
el.observe("mouseover", function (event) {
_selectedLinkEl = el;
_detailEl = event.element().next();
_detailEl.show();
_body.observe("mouseover", _bodyMouseOverFunction);
});
});
};
var _bodyMouseOverFunction = function (event) {
if (event.element() != _selectedLinkEl &&
event.element() != _detailEl &&
!event.element().ancestors().include(_detailEl)) {
_detailEl.hide();
_body.stopObserving("mouseover", _bodyMouseOverFunction);
}
};
return {
init: function () {
_init();
}
};
}();
I need to call my function App.UserSnapShot.init();through onready function of the same .. , So that to get this to work ..
How can i add a onReady function here.
Pls give some suggestions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的意思是?
You mean?
使用 jQuery...
$(document).ready(function(){
// 在此处插入在文档加载时运行的代码
});
Using jQuery...
$(document).ready(function(){
// Insert code to run on document load here
});