![](/img/trans.png)
[英]Included JS in the index.html is not working in main.js in VUE project
[英]onclick event working on index.html, but not on main.js
我的 index.html 文件中有一个 onclick 事件,如下所示:
<a onclick="startDraw('Point')" class="card-link" >Add Point</a>
如果我使用,它仅适用于 index.html 文件
<script>
function startDraw(point) {
console.log(point)
}
</script>
标签。
但是,如果尝试在 main.js 文件中定义它,则会显示以下错误:
未捕获的 ReferenceError:未在 HTMLButtonElement.onclick 处定义 startDraw((索引):59:56)
使用不显眼的事件处理程序,它起作用了。 谢谢@RoryMcCrossan
我刚转换
function startDraw(point) {
console.log(point)
}
对于这样的事情
var startDraw = document.getElementsByClassName("card-link");
for (var i = 0; i < startDraw.length; i++)
{
startDraw[i].onclick = function() // <-- line x
{
alert(this.getAttribute('data')); // <-- line y
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.