首页 > 解决方案 > 将html元素传递给JS库的方法

问题描述

调用方法:

document.getElementById("login_form").initLoginForm();

在“_myLibraryObject.initLoginForm”方法中获取login_form的对象:

(function(window){
    function myLibrary(){
        var _myLibraryObject = {};

        _myLibraryObject.initLoginForm = function(){
            alert(this); //get loginform object here
        };

        return _myLibraryObject;
    }

    if(typeof(window.myLib) === 'undefined'){
        window.myLib = myLibrary();
    }
})(window);

标签: javascripthtml

解决方案


推荐阅读