0

移動時間の値を取得して保存するにはどうすればよいですか。誰かがクリックするたびに加算されます

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;
4

1 に答える 1

0

誰かが #myImage をクリックしたときに move 関数を実行する場合は、イベント ハンドラーを使用します。高度なモデルを使用することも、オンロードに使用した従来のモデルを使用することもできます。

imgObj.onclick = moveRight; // do not execute
于 2012-06-21T18:02:36.967 に答える