Google chrome extension Chrome扩展:使用addEventListener()
在中,我被指示从HTML代码中删除内联事件处理程序(如onclick等),将它们移动到外部JS文件中,并改用addEventListener() 好的,我现在有一个background.html页面,看起来像这样Google chrome extension Chrome扩展:使用addEventListener(),google-chrome-extension,addeventlistener,Google Chrome Extension,Addeventlistener,在中,我被指示从HTML代码中删除内联事件处理程序(如onclick等),将它们移动到外部JS文件中,并改用addEventListener() 好的,我现在有一个background.html页面,看起来像这样 <html> <script type="text/javascript"> // Lots of script code here, snipped … </script> <body onload="checkInMyN
<html>
<script type="text/javascript">
// Lots of script code here, snipped
…
</script>
<body onload="checkInMyNPAPIPlugin('pluginId');">
<object type="application/x-mynpapiplugin" id="pluginId">
</body>
</html>
//这里有很多脚本代码,被剪掉了
…
按照另一个指令,我将大量脚本代码移动到一个单独的.js文件中,按照这个指令,我需要从body标记中删除onload=,而不是脚本代码中的cal addEventListener()。我试过几种方法,但显然我猜错了。那代码是什么样子的?特别是,在什么对象上调用addEventListener()
谢谢 我通常将此用于body onload事件
document.addEventListener('DOMContentLoaded', function () {
// My code here.. ( Your code here )
});
在某些方面,它是有效的。。但事实上,我认为我们应该使用
window.addEventListener('load', function () {
document.getElementById("#Our_DOM_Element").addEventListener('change - or - click..', function(){
// code..
});
});