JS 封閉式模式寫法 - TerryLee7788/JS_test GitHub Wiki
封閉式模式
- 要寫在body tag的結束標籤前面, 或者至少寫在你要選取的元素之後
var Terry = Terry || {};
Terry.test = (function(){
var input_tar = document.getElementById('txt1'),
div1 = document.getElementById('div1'),
showTxt = function(){
var _this = this,
val = _this.value;
div1.innerText = val;
},
init = function(){
input_tar.addEventListener('change', showTxt, false);
}
return {
init: init
};
})();
window.addEventListener('load', Terry.test.init, false);
P.S. JQ要傳JQ的參數