javascript - Javascript 对象文字模式,单击功能不起作用
问题描述
我是编码和尝试构建我的第一个插件的初学者。我现在遇到的问题是当我尝试使用我的点击功能时,它没有点击(它在测试方法的控制台内没有显示任何内容)。
这是我的代码
JS
;(function($){
var exampleObject = {
init: function() {
this.cacheDom();
this.bindEvents();
},
cacheDom: function() {
this.$examplebox = $("#exampleoneid");
this.$examplebutton = this.$examplebox.find("#button-example");
},
bindEvents: function() {
this.$examplebutton.on('click', this.test.bind(this));
},
test: function() {
console.log("hello");
}
};
exampleObject.init();
})(jQuery);
HTML
<div id="firstbox">
<div id="exampleoneid">
<input type="button" id="button-example">
</div>
</div>
它在 id 之后的页面上执行。希望有人知道问题/解决方案。
解决方案
推荐阅读
- javascript - 覆盖 Number.toLocaleString("fa-IR") 并更改波斯数字的千位分隔符
- javascript - bcrypt npm 安装错误 - 错误:找不到模块 node-pre-gyp\bin\node-pre-gyp
- verilog - 我是 Verilog 的新手,如果无法合成初始块,那么如何在不重置的情况下初始化寄存器,请有人解释
- c# - 从 .NET C# 访问 LinkedIn API V2
- json - 如何在 JSON 文件中翻译 Laravel 的默认验证错误?
- python - 使用 plotly 和 geojson 文件绘制地图
- neo4j - 基于本体的 Neo4J 动态 Spring 数据类
- python - 批准后如何将对象从 App A.Model A 复制到 App B.Model B 创建新对象并更新 App B Model B 中的一个字段
- typescript - TypeScript 中带有泛型的条件类型
- ssh - Jupyter:如何列出正在运行的内核以及哪个笔记本启动了它们?