我想要一个在页面加载时调用的函数,然后该函数会将监听器添加到页面上的 div 标记,监听器会将我的 javascript 文件中的全局变量更改为 true 或 false,但是我无法执行此操作,因为当我尝试执行此操作时收到关于函数严格的错误。
浏览器:Chrome
错误:
TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
查看代码:
<script>
$(document).ready(function () {
var imgs = document.querySelectorAll(".cut-images");
[].forEach.call(imgs, function (img) {
img.addEventListener("dragstart", dragStart, false);
img.addEventListener("dragend", dragEnd, false);
});
});
Javascript:
var isOnDiv = false;
function dragStart(e) {
this.style.opacity = "0.4";
document.getElementById("chuckImage").addEventListener("mouseenter", function () { isOnDiv = true; });
document.getElementById("chuckImage").addEventListener("mouseout", function () { isOnDiv = false; });
e.dataTransfer.effectAllowed = "move";
}
function dragEnd(e) {
if (isOnDiv === true)
alert("ding");
this.style.opacity = "1.0";
}
有谁知道为什么我的函数会抛出这个错误?
最佳答案
关于javascript - 为什么这个函数在 javascript 中抛出 'strict' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52501547/