我怎样才能获得它移动并保存多久的价值。因此,每当有人点击它时,它就会加起来
var imgObj = null;
function init(){
imgObj = document.getElementById('myImage');
imgObj.style.position= 'relative';
imgObj.style.left = '0px';
}
function moveRight(){
if(parseInt(imgObj.style.left) < 700){
imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';
}
if(parseInt(imgObj.style.left) == 700){
imgObj.style.left = parseInt(imgObj.style.left) + 0 + 'px';
}
}
window.onload =init;
答案 0 :(得分:0)
如果您希望在有人点击#myImage时执行移动功能,请使用event handler。您可以使用advanced model或traditional,因为您已将其用于onload。
imgObj.onclick = moveRight; // do not execute