2013-04-24 81 views
0

我是新来的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练习。预先感谢帮助家伙!

+0

按下“F12”,当您在浏览器的时候,你会看到被带到了一个控制台,错误最可能的状态,'”无法加载资源:资源未找到'',并且发生了'500服务器错误'。 – Ohgodwhy 2013-04-24 23:11:15

+1

那么,你需要包含jQuery(在你的例子中你不需要)。 – Niko 2013-04-24 23:12:56

+0

我复制并将上面的代码粘贴到[jsFiddle](http://jsfiddle.net/XNAKj/) – 2013-04-24 23:14:22

回答

2

你似乎并不被包括jQuery的:

<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 

而且,是d:\驱动硬盘驱动器或CD/DVD驱动器?这可能也是一个问题。

+0

解决了我的问题,谢谢! – JSCOTT12 2013-04-24 23:16:05

1

您应该引用jQuery库在HTML中:

<head> 
    <link type="text/css" rel="stylesheet" href="style.css"/> 
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
    <script type="text/javascript" src="file:///D:/Documents%20and%20Settings/stsc/My%20Documents/_prac/script.js"></script> 
    <title>Practice</title> 
</head> 
相关问题