Chrome扩展点击事件不执行

chrome扩展,在popup页面,给页面对象添加的onclick事件不执行。

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>chrome扩展测试</title></head>
<body>
<a onclick="alert('hello world!')">hello</a></body></html>

chrome扩展不支持inline-script,绑定事件的代码需要放到外部js文件中,也不能直接在DOM对象上添加click事件,改下面这样,onclick事件用外部js代码绑定

<a id="b" >hello</a>
<script src="b.js"></script>

b.js

document.getElementById('b').onclick=function(){alert('hello world!')}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632