我正在尝试创建一个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