querySelector() attachEvent() not working
querySelector() attachEvent() not working
我有一个类似下面的按钮
<input type="button" value="check" />
而且,我试着提醒点击这个按钮如下
document.querySelector('input[type="button"]').attachEvent('onclick', function() { alert(1); });
但这不起作用,为什么?
使用以下代码片段:-
document.querySelector('input[type="button"]').addEventListener('click', function() { alert(1); });
也许这些有帮助:
链接:http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_addeventlistener_crossbrowser
文件:http://www.w3schools.com/jsref/met_document_addeventlistener.asp
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working