如何使用页面加载时给出的 id 调用命名空间

How to call name space with id given on page load

本文关键字:id 调用 命名空间 何使用 加载      更新时间:2023-09-26

如何在页面加载时使用给定的 id 调用命名空间

我有以下命名空间

      var panel = panel || {};
        panel = (function() {
            var div_pass = function (id) {
                id_given=id;
            };
            var type = function(type_pass) {
                type_given=type_pass;
            };
            return {

                divid : function() {
                    return type_given;
                 }

            };
        }());

我在页面加载时将其称为

onload="panel.div_pass('window')"

这不会打电话div_pass我放警报,而是显示在div_pass

如果要

调用panel.div_pass,则需要在面板上返回div_pass。

return {
  divid : function() {
    return type_given;
  },
  div_pass: div_pass
};

试试这个

var panel = panel || {};
panel =  {
     divid : function() {
         return type_given;
     },
      div_pass:function(id){
          alert(id)
      }
};