楚河之界 2022-07-04 16:30 采纳率: 97.4%
浏览 33
已结题

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>
  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2022-07-04 16:36
    关注

    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!')}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 7月12日
  • 已采纳回答 7月4日
  • 创建了问题 7月4日