[英]How do I make div a clickable link?
So, I'm having trouble trying to figure out how to make the 2 left divs ( volunteer sign-up and Request a volunteer ) on my home page be clickable links. 因此,我很难弄清楚如何使主页上的左2个div( 志愿者注册和请志愿者 )成为可单击的链接。 I currently have them change color when you hover over them but how do I make them link to there appropriate page. 目前,当您将鼠标悬停在它们上面时,它们会更改颜色,但是如何使它们链接到相应的页面。 Any help w 任何帮助
Wrap the div in an anchor tag. 将div包裹在锚标记中。
<a href="your-link-here">
<div></div>
</a>
<div class="mydiv" data-href="http://stackoverflow.com"></div>
<script>
$('.mydiv').on('click', function(){
window.location = $(this).data('href');
})
</script>
this way you could use more than one clickable div 这样,您可以使用多个可点击的div
Give the div a class or other identifier. 给div一个类或其他标识符。 Then using jQuery do something like: 然后使用jQuery做类似的事情:
$('identifier').click(function(){
window.location = "your url";
});
None jQuery: 无jQuery:
<div id="hello"></div>
function linkTo(url){
window.location = url;
}
el = document.getElementById('hello');
el.onclick = linkTo('some website');
i can't see the link but you can do this using Javascript: 我看不到链接,但是您可以使用Javascript执行此操作:
<div style="cursor: pointer;" onclick="window.location='http://google.com/'">
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.