javascript - 将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);
解决方案
推荐阅读
- java - Android 通知点击打开应用程序仅适用于第一次
- python - 相交数字计算
- go - 如何逐字读取文件
- swift - 从父类继承的子类不改变颜色
- c# - ASP.Net 在后台编译期间显示启动图像
- ruby-on-rails - 猴子修补 Rails tag_helper 方法
- amazon-s3 - EMR 到 S3 文件写入给我错误 java.net.URISyntaxException:绝对 URI 中的相对路径
- php - PHP中数组上的未定义索引是否有“自动空”运算符?
- python - 如何将列表转换为这样的二维列表 [[1, 2, 3][4, 5, 6][7, 8, 9]]
- ruby - LoadError - 库版本不兼容 - /Users/user/gems/gems/ffi-1.13.1/lib/ffi_c.bundle