所以这段代码可以工作:
<script>
function animate() {
var x = 0;
var goUp = document.getElementById('rotationUp');
var comeDown = document.getElementById('rotationDown');
goUp.onmouseover = alert(x);
}
</script>
这不是:
<script>
function animate() {
var x = 0;
var goUp = document.getElementById('rotationUp');
var comeDown = document.getElementById('rotationDown');
goUp.onmouseover = function() {
alert(x);
}
}
</script>
唯一的区别是功能,我哪里出错了?
PS:我需要它作为一个函数来工作
最佳答案
尝试
function animate() {
var x = 0;
var goUp = document.getElementById('rotationUp');
var comeDown = document.getElementById('rotationDown');
goUp.onmouseover = function() {
alert(x);
}
}
关于javascript - 为什么这个动画功能不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18489270/