2013-04-24 85 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> 
相關問題