第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

入門(mén)JS自編簡(jiǎn)單圖像移動(dòng) 然而并沒(méi)辦法執(zhí)行 求解答 萬(wàn)分感謝!

入門(mén)JS自編簡(jiǎn)單圖像移動(dòng) 然而并沒(méi)辦法執(zhí)行 求解答 萬(wàn)分感謝!

KokoTa 2015-09-19 20:47:40
<!DOCTYPE html><html><head> <meta charset = "utf-8"> <title></title> <script type="text/javascript"> window.onload = function(){ var div = document.getElementById('div'); var img = div.getElementsByTagName('img'); var ten = 10; var input = document.getElementById('input'); input.onclick = function(){ setInterval(function(){ var left = parseInt(img[0].marginLeft); left += ten + 'px'; },100) } } </script> <style> #div{width:1000px; background: gray; display: block;position: absolute;} img{width: 100px;height: 100px; display: block;position: relative;} input{margin-top:100px;} </style></head><body><div id="div"> <img src="C:\Users\Administrator\Pictures\51607230_p0.png"></div><input type="button" value="click" id="input"></body></html>(不要在意圖片),為什么點(diǎn)了Input 圖不動(dòng)?
查看完整描述

1 回答

已采納
?
pardon110

TA貢獻(xiàn)1038條經(jīng)驗(yàn) 獲得超227個(gè)贊

  1. marginLeft在js中使用錯(cuò)誤,用style.marginLeft取值,注意:取值對(duì)象必須有相應(yīng)的內(nèi)聯(lián)樣式。

  2. 關(guān)鍵點(diǎn)獲取新值后,未給要移動(dòng)的對(duì)象添加值。

    修改后的代碼如下

  3. <!DOCTYPE?html>
    <html>
    <head>
    	<meta?charset?=?"utf-8">
    	<title></title>
    	<script?type="text/javascript">
    		window.onload?=?function(){
    			var?div?=?document.getElementById('div');
    			var?img?=?div.getElementsByTagName('img');
    			var?ten?=?10;
    			var?input?=?document.getElementById('input');
    			input.onclick?=?function(){
    					setInterval(function(){
    					var?left?=?parseInt(img[0].style.marginLeft);
    					left?+=?ten;
    					img[0].style.marginLeft?=?left+"px";
    				},100)
    			}
    			
    		}
    	</script>
    	<style>
    		#div{width:1000px;?background:?gray;?display:?block;position:?absolute;}
    		img{width:?100px;height:?100px;?display:?block;position:?relative;}
    		input{margin-top:100px;}
    	</style>
    </head>
    <body>
    <div?id="div">
    	<img?src="C:\Users\Administrator\Pictures\51607230_p0.png"?style="margin-left:0px">
    </div>
    <input?type="button"?value="click"?id="input">
    </body>
    </html>
查看完整回答
反對(duì) 回復(fù) 2015-09-22
  • 1 回答
  • 0 關(guān)注
  • 1701 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)