2014-05-24 110 views
-3

我正在嘗試與html中的按鈕進行對話,並且我使用jQuery來隱藏舊線條並顯示新線條。這樣,當你點擊一個按鈕時,yoa可以繼續「說話」。我在JSfiddle中開始了它,它完美地工作。但現在,我想把它放在一個真實的網站上,而jquery什麼都不做。在這裏,我有小提琴,其實際工作:http://jsfiddle.net/MeisterAbababa/xHk5g/207/。 我想我在做錯誤的HTML或使用ID不正確,但我不知道該怎麼做。Javascript不識別jQuery

編輯: 這些都是在瀏覽器的控制檯中的錯誤:

語法錯誤:語法錯誤jQuery的1.10.2.min.js:1周

的ReferenceError:$沒有定義Apple.js:2

(我可能犯了一個愚蠢的錯誤)。

<!DOCTYPE html> <html> <head> <title>Talking to Universe</title> <link href="Apples.css" rel="stylesheet" type="text/css" > <script type="text/javascript" src="jquery-1.10.2.min.js"></script> <script type="text/javascript" src="Apple.js"></script> 

</head> <body> <div ID="PT1" class="presentationtext">Good morning. 
    <button Id="PR1">Hello</button> </div> <div ID="PT2" class="presentationtext">I'm the Universe. Nice to meet you. 
    <button Id="PR2">The pleasure is mine</button> </div> <div ID="PT3" class="presentationtext">I'm boring here. Why you don´t get this coin? 
    <button Id="PR3">Get the coin</button> </div> <div ID="PT4" class="presentationtext">Oh. You can buy things. We are in space, so you can buy almost everything. Let´s start buying an apple farm and an Apple Button. 
    <button Id="PR4">Get the things you have said with the coin you gave me.</button> 

</div></div> 
</body> 
</html> 

也是她的劇本:

//Menu $("#TableClicker").css(); 
$(document).ready(function() { 
    $("#PR1").click(function() { 
     $("#PT2").css("visibility", "visible"); 
     $("#PT1").hide(); 
    }); 
    $("#PR2").click(function() { 
     $("#PT3").css("visibility", "visible"); 
     $("#PT2").hide(); 
    }); 
    $("#PR3").click(function() { 
     $("#PT4").css("visibility", "visible"); 
     $("#PT3").hide(); 
    }); 
    $("#PR4").click(function() { 
     $("#MenuButton").css("visibility", "visible"); 
     $("#AppleFarmButton").css("visibility", "visible"); 
     $("#TableClicker").css("visibility", "visible"); 
     $("#PT4").hide(); 
    }); 
    $("#MenuButton").click(function() { 
     $("#TableClicker").hide(); 
    }); 
    $("#AppleFarmButton").click(function() { 
     $("#TableClicker").show(); 
    }); 
}); 

這裏是CSS:

/*Presentation*/ 
.presentationtext{ 
} 
#PT1{ 
    visibility:visible; 
} 
#PT2{ 
    visibility:hidden; 
} 
#PT3{ 
    visibility:hidden; 
} 
#PT4{ 
    visibility:hidden; 
} 
+1

-1爲壞問題標題,請爲您的問題寫一個內容豐富的標題。 –

+0

你在你的實際網頁中包含jQuery嗎?瀏覽器錯誤控制檯或調試器控制檯中報告了哪些錯誤?你確定你的腳本正確加載嗎? – jfriend00

+0

@ jfriend00我添加了錯誤。是的,鏈接到html頭部的jquery腳本。 – MeisterAbababa

回答

2

看來,jQuery是沒有成功加載在你的頁面。

這種情況最可能的原因是jquery-1.10.2.min.js沒有正確放置在同一個目錄服務器上爲您的HTML網頁,所以瀏覽器沒有找到它,當你指定這個<script>標籤:

<script type="text/javascript" src="jquery-1.10.2.min.js"></script> 
+0

是的,就是這樣。謝謝。 – MeisterAbababa

+0

@MeisterAbababa - 任何時候某些事情不能按照我的預期工作,我要做的第一件事就是檢查瀏覽器調試控制檯是否有錯誤。它通常包含導致問題的線索。 – jfriend00