我正在嘗試創建一個onmosueover事件,以便在將鼠標懸停在其上時將圖片從一個圖像更改爲另一個圖像。我知道如何在ASPX做到這一點,我不喜歡的東西如下:動態交換ASP.Net圖像OnMouseOver事件
<td style="display: block; width: 320px;" valign="top">
<img style="margin: 3px; border: 0px solid #000000;" src='/Shop/Images/2.jpg' alt="Robot Kit" width="303px" id="previewImg" />
<br />
<table cellpadding="0" cellspacing="6">
<tr>
<td>
<img src='1.jpg' style="width: 70px; border: 1px solid #e8e8e8;" onmouseover="document.getElementById('previewImg').src='1.jpg';" onmouseout="document.getElementById('previewImg').src='2.jpg';" />
</td>
<td>
<img src='head.jpg' style="width: 70px; border: 1px solid #e8e8e8;" onmouseover="document.getElementById('previewImg').src='head.jpg';" onmouseout="document.getElementById('previewImg').src='2.jpg';" />
</td>
</tr>
</table>
現在我試圖使它的動態,我從數據庫中提取的圖像參考號碼。我使用的ASP:圖片標籤,到目前爲止,我有這樣的事情在我的.cs頁面如下:
imgItem.ImageUrl = string.Format("Images/{0}.jpg", id);
imgItem.Width = new Unit(150, UnitType.Pixel);
imgItem.Attributes.Add("onmouseover", "javascript:swapImageIn('Shop/Images/3.JPG');return true;");
imgItem.Attributes.Add("onmouseout", "javascript:swapImageOut('imgItem');return true;");
imgItem2.ImageUrl = string.Format("Images/{0}.jpg", 3);
imgItem2.Width = new Unit(150, UnitType.Pixel);
但是我不知道在哪裏把它形成在這裏。代碼絕對不完整,我被卡住了。任何幫助將不勝感激。謝謝!
您是否打算在鼠標不在的時候用原來的圖像替換大圖像?或者像離開一樣。像這樣 - http://www.amazon.com/Pro-ASP-NET-Web-API-Security/dp/1430257822/ – Win 2013-05-10 19:06:24
是的,我打算用鼠標替換原來的大圖像。所以它只會改變鼠標懸停在圖像上的圖像,然後回到原始圖像。感謝您的任何建議 – ghawes 2013-05-10 19:16:31