使用使用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也没有显示,也没有链接工作,任何想法。

感谢 让

+0

待办事项你有任何进一步的信息问题?使用你的例子,它适用于我 - 无论是在IE和Firefox的光标和链接。您的jQuery库是否在页面上正确引用? – CraigTP 2010-08-03 07:52:06

+0

这应该工作,[演示](http://jsfiddle.net/W3c5V/) – Reigel 2010-08-03 07:53:45

+0

我正在使用铬 – X10nD 2010-08-03 07:56:23

确保你包你的代码ready handler这样的:

$(function(){ 
    $('#logo').bind('click',function() { 
    window.location = "index.php" 
    }); 
}); 
+0

任何特定的原因,通常这就是我写的代码 – X10nD 2010-08-03 07:57:28

+1

@Jean:你需要指定将你的代码包装在就绪处理程序中,以便当DOM变成准备就绪后,您的代码应该可以在例如点击标志时运行。更多信息:http://api.jquery。com/ready/ – Sarfraz 2010-08-03 08:03:20

+0

我不明白,你的代码与我的代码有什么不同 – X10nD 2010-08-03 08:08:07

使用,

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 */ 
} 

看起来像你“的index.php”后缺少一个分号

+0

分号现在不是问题..;) – Reigel 2010-08-03 07:56:03

注册您的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)对它进行了测试,光标显示正确。

添加display:block;到你的CSS

看到这里的工作示例

http://jsfiddle.net/4ceK4/

+0

div已经是一个阻塞的元素) – Reigel 2010-08-03 07:57:35

+0

我知道,但它工作时,我把它,奇怪 – Starx 2010-08-03 08:03:16

+0

是的!并且在我移除它时仍然在工作。 – Reigel 2010-08-03 08:07:03