簡體   English   中英

如何獲得在瀏覽器上運行的JQuery代碼?

[英]How do I get JQuery code to run on my browser?

我是JQuery的新手,我試圖弄清楚如何使.mouseenter()和.mouseleave()方法正常工作。 到目前為止,我已經嘗試使用IE8和FF,但是由於某些奇怪的原因,除了保持靜態之外,我無法讓元素做任何事情。 這是我到目前為止的代碼:

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進行練習的簡單示例。 在此先感謝您的幫助!

您似乎沒有包括jQuery:

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

另外,D:\\驅動器是硬盤驅動器還是CD / DVD驅動器? 這也可能是一個問題。

您應該在HTML內引用jquery庫:

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM