HTML - 如何使整个 DIV 成为超链接? [英] HTML - how to make an entire DIV a hyperlink?
本文介绍了HTML - 如何使整个 DIV 成为超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使整个 DIV
成为可点击的超链接.意思是,我基本上想做:
<div>...</div><table><tr>..</tr></table>....
每当有人将鼠标悬停在 myclass DIV
上时,我都希望整个 DIV
成为一个可点击的超链接.
解决方案
您可以将 JavaScript 的 onclick 添加到 div 中.
<div onclick="location.href='newurl.html';"> </div>
用于新窗口
<div onclick="window.open('newurl.html','mywindow');"style="cursor: pointer;"> </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>
And whenever someone mouse hovers of the myclass DIV
, I want the entire DIV
it to be a clickable hyperlink.
解决方案
You can add the onclick for JavaScript into the div.
<div onclick="location.href='newurl.html';"> </div>
EDIT: for new window
<div onclick="window.open('newurl.html','mywindow');" style="cursor: pointer;"> </div>
这篇关于HTML - 如何使整个 DIV 成为超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文