我在angularjs application
工作。要通过提醒消息显示未保存的更改,我们已使用window.event.target. Everything works fine in all browsers but
Firefox . The
错误is
window.event未定义。你以前遇到过这个问题吗?你有什么建议可以解决吗?请帮助我们。
<!DOCTYPE html>
<html>
<body>
<input value="click" type="button" onclick="call()" />
<script>
function call() {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
}
</script>
</body>
</html>
答案 0 :(得分:0)
与Chrome不同,事件参数必须在Firefox中定义
<!DOCTYPE html>
<html>
<body>
<input value="click" type="button" onclick="grabId(event)" />
<script>
function grabId(event) {
var targ;
if (!e) var e = event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
}
</script>
</body>
</html>
答案 1 :(得分:0)
以下应该可以正常工作:
<!DOCTYPE html>
<html>
<body>
<script>
function call(e) {
var targ;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
}
</script>
<input value="click" type="button" onclick="call(e)" />
</body>
</html>