天天看點

js通過擷取id和name改變圖檔

<a target="_blank" href="http://blog.51cto.com/attachment/201207/112813423.jpg"></a>

&lt;html&gt; 

&lt;head&gt; 

&lt;script type="text/javascript"&gt; 

&lt;!-- 

function one(){ 

  document.getElementById('ok').style.background='url(http://d.lanrentuku.com/down/png/1205/angrybirds.jpg)'; 

function two(){ 

  document.getElementById('ok').style.background='url(http://d.lanrentuku.com/down/png/1110/angry_birds.jpg)'; 

function first(){ 

  document.yes.src='http://d.lanrentuku.com/down/png/1205/angrybirds.jpg'; 

function second(){ 

  document.yes.src='http://d.lanrentuku.com/down/png/1110/angry_birds.jpg'; 

//--&gt; 

&lt;/script&gt; 

&lt;/head&gt; 

&lt;body&gt; 

&lt;div id="ok" onMouseover="one()" onMouseout="two()" style="height:150px;width:550px;border:1px solid #ccc;background:#ddd"&gt;通過擷取id變換&lt;/div&gt; 

&lt;hr /&gt; 

&lt;a href="#"&gt; 

    &lt;img src="http://www.baidu.com/img/baidu_jgylogo3.gif" name="yes" onmouseOver="first()" onmouseOut="second()" border="0" /&gt; 

&lt;/a&gt; 

&lt;/body&gt; 

&lt;/html&gt; 

      本文轉自許琴 51CTO部落格,原文連結:http://blog.51cto.com/xuqin/948828,如需轉載請自行聯系原作者

繼續閱讀