2010-07-29 156 views
1

我需要放置一个广告作为我的网页的背景图片。使身体背景图像成为可点击链接的最佳方式是什么?css正文背景图片可点击

+0

dup:http://stackoverflow.com/questions/834579/how-can-i-make-a-background-clickable – 2010-07-29 08:24:15

回答

1

您无法创建可点击的背景图片。你的形象占据了整个身体空间吗?

+0

背景图片显示在页面内容的左右两列。这是需要点击的部分 – user75898 2010-07-29 08:40:54

+0

Maris解决方案应该可以工作。 – 2010-07-29 08:44:51

1

或者你也可以使用JavaScript:

$("body").click(function(event){ 
    event.stopPropagation(); 
    alert('oh hai'); 
}); 
+0

这显示弹出式菜单,当在网页 – Riho 2012-06-26 14:29:01

+0

@ Riho上点击任何地方时,就是这个例子中的行为。您可以用您需要的任何东西替换alert()函数。 – 2012-06-27 04:57:16

+0

我的意思是它应该只在点击背景图片时显示警报,而不是在内容中 – Riho 2012-07-02 12:53:36

0

这是我如何让身体背景图片可点击:

$('body').css({'background': 'url(yourimage.jpg) top center no-repeat'}) 
     $('body').click(function(e){ 
      if (e.target === this) { 
       window.open('http://link.html', '_blank'); 
      } 
}); 

您还可以使用window.location的,而不是window.open( )。希望这可以帮助。