我想让它的整个div是可点击的,并链接到另一个页面时,点击没有JavaScript和有效的代码/标记。
如果我得到的是我想要的结果-
<a href="#">
<div>This is a link</div>
</a>
W3C验证器说块元素不应该放在内联元素中。有没有更好的方法来做这件事?
发布于 2012-11-28 17:39:53
<div onclick="location.href='#';" style="cursor: pointer;">
</div>
发布于 2012-12-07 18:31:37
没有JS,我是这样做的:
我的HTML:
<div class="container">
<div class="sometext">Some text here</div>
<div class="someothertext">Some other text here</div>
<a href="#" class="mylink">text of my link</a>
</div>
我的CSS:
.container{
position: relative;
}
.container.a{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
text-indent: -9999px; //these two lines are to hide my actual link text.
overflow: hidden; //these two lines are to hide my actual link text.
}
发布于 2011-11-17 08:08:30
jQuery将允许您这样做。
查找click()
函数:http://api.jquery.com/click/
示例:
$('#yourDIV').click(function() {
alert('You clicked the DIV.');
});
https://stackoverflow.com/questions/8160494
复制相似问题