Javascript css身体背景图像可点击

Javascript css身体背景图像可点击,javascript,html,css,Javascript,Html,Css,我需要放置一个广告作为我的网页背景图像。让身体背景图像成为可点击链接的最佳方式是什么?你不能让背景图像成为可点击链接。您的图像是否占据了整个身体空间?或者您可以使用javascript: $("body").click(function(event){ event.stopPropagation(); alert('oh hai'); }); 这是我如何使身体背景图像可点击的: $('body').css({'background': 'url(yourimage.jpg)

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

你不能让背景图像成为可点击链接。您的图像是否占据了整个身体空间?

或者您可以使用javascript:

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

这是我如何使身体背景图像可点击的:

$('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()。希望这有帮助。

dup:背景图像显示在页面内容的左右两侧。这是需要改进的部分clickable@Riho,这是本例中的意图行为。你可以用你需要的任何东西来替换alert()函数。我的意思是,它应该只在背景图像上单击ikng时显示alert,而不是在内容中