index.js中监听事件没反应
来源:4-2 创建添加音乐窗口

alex__wyh
2019-06-12
- 我在html文件中给添加按钮设置一个id
- 然后在js文件中给这个按钮绑定一个事件
- 然后当我点击按钮时,这个事件没有被触发(控制台没输出消息),下面是代码
index.html的代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>本地播放器</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-4">
<h1>我的播放器</h1>
<button type="button" id="add-music-button" class="btn btn-primary btn-lg btn-block mt-4">
添加歌曲到曲库
</button>
</div>
<script>
require('./index.js')
</script>
</body>
</html>
index.js的代码
const {ipcRenderer} = require('electron')
document.getElementById('add-music-button').addEventListener('click', () => {
console.log('hello from index')
ipcRenderer.send('add-music-window')
})
写回答
3回答
-
同学你好,你说的控制台是浏览器的控制台?还是你的 terminal?
012019-06-13 -
yuzhewo
2019-06-13
打开devtools看下,渲染进程中的输出是在调试工具中输出的 hello from index
012019-06-13 -
yuzhewo
2019-06-13
遇到同样的问题,注意文件保存,然后重新启动程序有时候问题就会解决,不一定是代码的问题。
00
相似问题
script中的require引用没效果
回答 4
5-2 点击【导入音乐】按钮没有反应
回答 4