我正在删除我的 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 函数。
请给一些建议
最佳答案
你的意思是?
App.onReady = function() {
App.UserSnapShot.init();
};
document.observe("dom:loaded", App.onReady);
关于用于调用 Namespace 函数的 Javascript Onready 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4201859/