html Javascript通过onmouseover移动图像<;a>;按钮

html Javascript通过onmouseover移动图像<;a>;按钮,javascript,html,element,move,getelementbyid,Javascript,Html,Element,Move,Getelementbyid,我是一个愚蠢的网站创建者,我在javascript上遇到了一些问题。我在互联网上找到了一个功能,现在我正在将它与更多的东西结合起来。 但它根本不起作用。我对javascript没有太多经验 Javascript文件: function getOff(){z = this.ElementId; x = document.getElementById('button_shadow' + z); return x.offsetLeft;} function move_right(value){v

我是一个愚蠢的网站创建者,我在javascript上遇到了一些问题。我在互联网上找到了一个功能,现在我正在将它与更多的东西结合起来。 但它根本不起作用。我对javascript没有太多经验

Javascript文件:

function getOff(){z = this.ElementId;
 x = document.getElementById('button_shadow' + z);
 return x.offsetLeft;}

function move_right(value){var y = getOff();
 x.style.left = y + value;}
html:


谢谢。

您可以简化和改进代码。您只能保留这一功能:

function move_right(obj, value) {
    var x = document.getElementById('button_shadow' + obj.id);
    x.style.left = x.offsetLeft + value + 'px';
}
并在HTML中使用它,如下所示:

<a id="1" onmouseover="move_right(this, 5);" ...>O klubu</a>

错误:应该使用
id
属性,而不是
ElementId
。如果像这样调用函数,那么函数中的上下文将是窗口,而不是与之交互的目标元素。因此,您可以简单地传递引用对象
this
以用于检索
id

function move_right(obj, value) {
    var x = document.getElementById('button_shadow' + obj.id);
    x.style.left = x.offsetLeft + value + 'px';
}
<a id="1" onmouseover="move_right(this, 5);" ...>O klubu</a>