本文介绍了使Div成为链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个div,我想点击。每个div都有一个锚链接,我想在其中使用每个div的链接。
I have two div's which I would like to be clickable. Each div has an anchor link within which I would like to use for each div's link.
我使用的帮助下面的左div,但不是正确的。
I'm using the help below which works for the left div but not the right.http://css-tricks.com/snippets/jquery/make-entire-div-clickable
不太确定我遗漏了什么,或者有更好的方法吗?理想情况下,我想使用CSS,但这个选项仍然可以工作,即使js被禁用。
Not quite sure what I'm missing or if there is a better way to do this? Ideally I would like to use just CSS but this option would still work even if js is disabled.
任何帮助将是巨大的。
$('.left').click(function(){
window.location=$(this).find("a").attr("href");
return false;
});
$('.right').click(function(){
window.location=$(this).find("a").attr("href");
return false;
});
<div class="left">
<div class="left-content">
<h2><a href="#">title</a></h2>
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
<div class="right">
<div class="right-content">
<h2><a href="#">title</a></h2>
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
推荐答案
将DIV放入锚中在HTML5中有效向后兼容其他DOCTYPES。
Putting DIVs inside of anchors is valid in HTML5 and is backwards compatible with other DOCTYPES.
<a href="#">
<div class="right">
<div class="right-content">
<h2>title</h2>
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
</a>
这篇关于使Div成为链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!