未捕获的类型错误:对象#<HTMLDivElement>没有方法'绑定'
Uncaught TypeError: Object #<HTMLDivElement> has no method 'bind'
我在网上搜索了解决方案。我试过使用"on"、"click",但不起作用。
var element = document.createElement( 'div' );
element.className = 'element';
element.style.backgroundColor = 'rgba(0,127,127,' + ( Math.random() * 0.5 + 0.25 ) + ')';
element.style.cursor = 'pointer';
element.bind("click", function(e){ alert("testing"); });
从上面的代码中,它将显示Uncaught TypeError: Object #<HTMLDivElement> has no method 'bind'
。如果我将bind事件更改为element.click(function(){alert("testing")});
,代码工作正常,但单击时不会显示警告框。
要添加事件侦听器,需要使用.addEventListener(),.bind()用于将自定义执行上下文传递给函数
element.addEventListener("click", function(e){ alert("testing"); });
相关文章:
- 在<页眉>标签
- 如何更改<svg>标记为<img>用js标记
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- Ajax文件加载和<输入>文件加载
- 检测电话窃听,即:<a href="电话:xxx">在UIWebview上
- 链接所有<a>Meteor
- 在<输入类型=“;文件“/>
- Div根据<选择>菜单
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- 如何首先设置样式<td>表中包含在窗体中的元素
- 通过点击<李>在jQuery中
- 正在检测导航到<a name=“;最新主题”></a>
- 如何更改<选择>使用angularJS从控制器获得的值
- 通过具有IE<11
- 未捕获的类型错误:对象#<HTMLDivElement>没有方法'偏移'
- 未捕获的类型错误:对象#<HTMLDivElement>没有方法'addPanel'
- MooTools Slider控件,TypeError:Object#<HTMLDivElement>没有方
- 未捕获的类型错误:对象#<HTMLDivElement>没有方法'绑定'
- Mootools元素>对象# & lt; HTMLDivElement>没有方法'addEvent'
- 对象# & lt; HTMLDivElement>没有方法'remove'