[英]onmouseover wont work with my function?
I am currently learning to use java script, and have come across a problem I cant solve. 我目前正在学习使用java脚本,并遇到了一个我无法解决的问题。 in a simple HTM for the sake of practice I have made an script that modifies the top margin of a div:
在一个简单的HTM中为了练习我已经制作了一个修改div的上边距的脚本:
var boton = (function () {
var timerId;
return function (margin, element) {
var i = 2;
timerId = setInterval (function () {
if (i > margin)
i = 2;
element.style.marginTop = i + 'px';
i++;
}, 100);
}; }) ();
If I call the function this way it works: 如果我以这种方式调用函数它可以工作:
<script type="text/javascript">
boton (50 , document.getElementById("botondiv"));
</script>
But if I try to call it within a mouseover event on an A tag it wont work 但是,如果我尝试在A标签上的鼠标悬停事件中调用它,它将无法工作
<a onmouseover="boton (50 , document.getElementById("botondiv"));" href="#"></a>
My idea on this is that when some one hovers over the A tag the top margin of the element is modified. 我的想法是,当有人在A标签上盘旋时,元素的上边距会被修改。 what am I doing wrong?
我究竟做错了什么?
Well, you have quotes inside quotes with no escaping, for one. 好吧,你有引号内的引号,没有逃避,一个。
<a onmouseover="boton (50 , document.getElementById("botondiv"));" href="#"></a>
Should be: 应该:
<a onmouseover="boton (50 , document.getElementById('botondiv'));" href="#"></a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.