0
創建命名空間,我在js文件錯誤在jQuery的
(function ($) {
var $r = $.loadaccess;
jQuery.loadaccess.page.user = {
init: function() {
debugger;
var k = 'dd';
alert(k);
}
};
})(jQuery);
var user = jQuery.loadaccess.page.user;
寫代碼,我叫它.aspx頁面中
$(document).ready(function() {
jQuery.loadaccess.page.user.init();
});
上,但它拋出的錯誤我 「Microsoft JScript中的運行時錯誤:無法獲取屬性「頁面」的值:對象爲空或未定義「
on this
jQuery.loadaccess.page.user = {
init: function() {
debugger;
var k = 'dd';
alert(k);
}
};
JQuery.loadaccess.page.user是我的命名空間 – Pankaj 2013-04-21 15:50:19
Javascript中的'namespaces'只是對象。如果對象不存在,則無法在對象上創建屬性。因此,如果你嘗試'jQuery.loadacccess.something',它將會出錯,因爲'loadaccess'對象不存在。您將需要手動創建您的名稱空間的所有級別(包括'loadaccess'對象)。我已經更新了我的答案。 – badsyntax 2013-04-21 15:52:52