使用使用jQuery
问题描述:
为纽带的div背景图片我已经把一个标志作为背景图像在一个div使用使用jQuery
<div id="logo" style="background-image:url(images/logo.jpg); position:absolute; top:20px; left:18%; width:275px; height:100px; cursor:pointer;"></div>
我想使用jQuery
// jQuery代码以此为DIV为纽带
$('#logo').bind('click',function() {
window.location = "index.php"
});
cursor:pointer
也没有显示,也没有链接工作,任何想法。
感谢 让
答
确保你包你的代码ready handler这样的:
$(function(){
$('#logo').bind('click',function() {
window.location = "index.php"
});
});
答
使用,
window.location = "index.php"
window.location.replace("index.php")
代替和代替.bind,只需使用。点击事件。
答
你不需要jQuery/JavaScript,只需使用HTML和CSS即可。
<a href="index.php" id="logo">Blabla</a>
#logo {
display: block;
background-image: url(img/foo.png);
text-indent: -9999em;
overflow: hidden;
width: 300px; /* width of image goes here */
height: 300px; /* height of image goes here */
}
答
注册您的click
事件处理程序在ready
事件处理程序如下,它会工作:
$(document).ready(function() {
$("#logo").click(function() {
window.location = "index.php";
});
});
关于你的CSS问题,我已经使用Google Chrome(5.0.375.125),Opera(10.60)和Internet Explorer(8.0)对它进行了测试,光标显示正确。
答
待办事项你有任何进一步的信息问题?使用你的例子,它适用于我 - 无论是在IE和Firefox的光标和链接。您的jQuery库是否在页面上正确引用? – CraigTP 2010-08-03 07:52:06
这应该工作,[演示](http://jsfiddle.net/W3c5V/) – Reigel 2010-08-03 07:53:45
我正在使用铬 – X10nD 2010-08-03 07:56:23