[英]How to make an image in a table cell clickable
I am a beginner programmer and am struggling to figure out how to make an image clickable. 我是一名初学者程序员,并且正在努力寻找如何使图像可点击的方法。
I have a set of images that I placed into a table, because that is the layout I need. 我将一组图像放到一张桌子上,因为这是我需要的布局。 The goal is to get linked to another pages once a certain image from the table is selected. 目标是一旦从表中选择了某个图像,便链接到另一个页面。 So far this is what I have (with multiple cells): 到目前为止,这就是我所拥有的(具有多个单元格):
<table border="0">
<tr>
<td>
<a>
<img src="img1.jpg" width="400" height="178" class="next" onclick="change('http://www.google.com')"/>
</a>
<div class="imgText"> Image 1 </div></td>
</tr>
</table>
Instead of onclick
, why not use href
of link: 代替onclick
,为什么不使用链接的href
:
<a href="http://www.google.com"><img src="img1.jpg" width="400" height="178" class="next" /></a>
Although with JavaScript, you would use window.location
: 虽然使用JavaScript,但您可以使用window.location
:
onclick="window.location = 'http://www.google.com'"
if you have somewhere in your code: 如果您的代码中有某处:
<script>
...
function change(location){
window.location = location;
}
...
it should work. 它应该工作。 Also Blaster's response is very good, keep in mind to give the image border=0. 另外,Blaster的响应非常好,请记住将图像的边框设置为= 0。 Images in tags with the hreh attribute set get borders on some browsers. 设置了hreh属性的标记中的图像在某些浏览器上会出现边框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.