HTML - 如何使整个DIV成为超链接? [英] HTML - how to make an entire DIV a hyperlink?

查看:1030
本文介绍了HTML - 如何使整个DIV成为超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何制作整个 DIV 可点击的超链接。这意味着,我基本上想这样做:

How do I make an entire DIV a clickable hyperlink. Meaning, I essentially want to do:

<div class="myclass" href="example.com">
    <div>...</div>
    <table><tr>..</tr></table>
    ....
</div>

每当鼠标悬停在myclass DIV ,我希望整个 DIV 它是一个可点击的超链接。

And whenever someone mouse hovers of the myclass DIV, I want the entire DIV it to be a clickable hyperlink.

推荐答案

您可以将JavaScript的onclick添加到div中。

You can add the onclick for JavaScript into the div.

<div onclick="location.href='newurl.html';">&nbsp;</div>

编辑:为新窗口

<div onclick="window.open('newurl.html','mywindow');" style="cursor: pointer;">&nbsp;</div>

这篇关于HTML - 如何使整个DIV成为超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆