怎么在javascript中设定图片的链接?

jaycool 2003-09-29 06:12:15
怎样在javascript中给图片指定类似<a href="test"></a>的效果?
...全文
90 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
superlionet 2003-09-30
  • 打赏
  • 举报
回复
...
document.images[loop].onclick=gotourl(url);
...


function gotourl(url){
document.location.href=url;
}
gen2 2003-09-29
  • 打赏
  • 举报
回复
<img src="test.jpg" style="cursor:hand" onclick="self.location='test.htm'")>
jaycool 2003-09-29
  • 打赏
  • 举报
回复
谢谢回复。下面这段代码是用来实现图片超过大小自动缩放的,我想要实现:

<script language="JavaScript" src="includes/default_javascript.js" type="text/javascript"></script>
<script language="Javascript">
function resizeImages()
{
if (document.images.length > 0) //Has images, validate sizes
{
var imgHeight;
var imgWidth;
for (var loop = 0; loop < document.images.length; loop++)
{
if (document.images[loop].name.substring(0,6) == 'chkImg')
{
imgWidth = document.images[loop].width;
imgHeight = document.images[loop].height;

if (imgWidth > <% = intImgWidth %>)
{
document.images[loop].width = <% = intImgWidth %>;
//Proportionalize Height
imgHeight = imgHeight / (imgWidth/<% = intImgWidth %>);
document.images[loop].height = imgHeight;

想在这个地方给图片指定一个链接,点击后在新窗口打开图片本身,应该怎么写?
}
}
}
}
}
</script>
zhjzh_zjz 2003-09-29
  • 打赏
  • 举报
回复
不是一样吗?这部就给图片加上了连接?
<a href="test"><img src="test.jpg"></a>

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧