HTML - 如何使整个 DIV 成为超链接?

标签 html xhtml hyperlink

<分区>

如何使整个 DIV 成为可点击的超链接。意思是,我本质上想做的是:

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

每当有人将鼠标悬停在 myclass DIV 上时,我希望整个 DIV 成为一个可点击的超链接。

最佳答案

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

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

编辑:新窗口

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

关于HTML - 如何使整个 DIV 成为超链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2188272/

相关文章:

javascript - 使用 JavaScript 提交 HTML 表单确认 Google Chrome 上的延迟

html - 单击链接时页面意外向上滚动

母版页中的 ASP.NET CSS 文件

jsf - IE9渲染 IE8文档标准

twitter-bootstrap - 带href的跨度 Bootstrap 字形图标

html - <pre> 标签中的额外空格

html - tpl文件中 "{# ... #}"标签是什么意思?

javascript - 当显示元素而不是实际值时,元素偏移返回 0

javascript - JavaScript Hook 的 HTML 元素

html - CSS - 100% 不透明表格单元格超过 95% 不透明度背景图像