【问题标题】:Javascript Onready function to call the Namespace functionJavascript Onready 函数调用 Namespace 函数
【发布时间】:2010-11-17 05:50:12
【问题描述】:

我正在删除我的 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 函数。

请给点建议

【问题讨论】:

  • 所有这些下划线!!啊啊啊啊啊啊!!!!!!
  • @jacob 我给了 _variablename 的私有变量
  • onready function of the same 是什么意思?请详细说明您想要什么。

标签: javascript namespaces onready


【解决方案1】:

你是说?

App.onReady = function() {
    App.UserSnapShot.init();
};

document.observe("dom:loaded", App.onReady);

【讨论】:

    【解决方案2】:

    使用 jQuery...

    $(document).ready(function(){ // 在此处插入代码以在文档加载时运行 });

    【讨论】:

      猜你喜欢
      • 2019-06-01
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-07
      • 2023-03-31
      • 1970-01-01
      相关资源
      最近更新 更多