我是新来的JQuery,我想弄清楚如何让我的.mouseenter()和.mouseleave()方法工作。到目前为止,我已经尝试过使用IE8和FF,但由于一些奇怪的原因,我无法让我的元素除了保持静态以外的任何其他功能。下面是我到目前为止的代码:如何获取JQuery代码在我的浏览器上运行?
HTML:
<!Doctype html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script type="text/javascript" src="file:///D:/Documents%20and%20Settings/stsc/My%20Documents/_prac/script.js"></script>
<title>Practice</title>
</head>
<body>
<div id="red"></div>
<div id="yellow"></div>
<div id="green"></div>
</body>
</html>
CSS:
div{
height:100px;
width: 100px;
border-radius: 50px;
}
#red{
background-color: red;
}
#yellow{
background-color: yellow;
}
#green{
background-color: green;
}
JS:
$(document).ready(function(){
$('div').mouseenter(function(){
$(this).animate({
width: '+=10px'
});
});
$('div').mouseleave(function(){
$(this).animate({
width: '-=10px'
});
});
$('div').click(function() {
$(this).toggle(1000);
});
});
这只是一个简单的例子使用jQuery练习。预先感谢帮助家伙!
按下“F12”,当您在浏览器的时候,你会看到被带到了一个控制台,错误最可能的状态,'”无法加载资源:资源未找到'',并且发生了'500服务器错误'。 – Ohgodwhy 2013-04-24 23:11:15
那么,你需要包含jQuery(在你的例子中你不需要)。 – Niko 2013-04-24 23:12:56
我复制并将上面的代码粘贴到[jsFiddle](http://jsfiddle.net/XNAKj/) – 2013-04-24 23:14:22