2014-02-17 55 views
-3

我試圖隱藏,顯示,移動圖像,但我無法做任何事情。我看到按鈕,但沒有發生任何事情。 jQuery的鏈接是錯誤的還是其他的東西?我所做的沒有任何事情似乎有效。不知道在這一點上做的......我無法讓jQuery工作。我錯過了什麼?

<html lang="en-us"> 

<head> 
    <meta charset="utf-8"> 
    <title>jQuery</title> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
    <link type="text/css" rel="stylesheet" href="jquery.css"/> 

      <script type="text/javascript"> 
     $(document).ready(function() { 
     $("img").addClass("wrappedElement"); 


     $("#Hide All Images").click(function(){ 
     $("img").hide("fast"); 
     }); 

     $("#Show All Images").click(function(){ 
     $("img").show("fast"); 
     }); 

     $("#Show Even Images").click(function() { 
     if ($("img:even").is(':visible') && $("img:odd").is(':visible')) { 
      $("img:odd").toggle("fast"); 
     }else{ 
      $("img:even").show("fast"); 
     } 
     }); 

     $("#Show Odd Images").click(function(){ 
     if ($("img:odd").is(':visible') && $("img:even").is(':visible')) { 
      $("img:even").toggle("fast"); 
     }else{ 
      $("img:odd").show("fast"); 
     } 
     }); 

     $("#Right Shift").click(function(){ 
     $("img").slideRight(); 
     }); 

     $("#Left Shift").click(function(){ 
     $("img").slideLeft(); 

     }); 
     }); 

    </script> 

<body> 


    <div id="header"> 
     <button id="Hide All Images">Hide All Images</button> 
     <button id="Show Even Images">Show Even Images</button> 
     <button id="Show Odd Images">Show Odd Images</button> 
     <button id="Right Shift">Right Shift</button> 
     <button id="Left Shift">Left Shift</button> 
    </div> 

    <div id ="content"> 
    <img class="photo" src="photo_one.jpg" alt="one"> 
    <img class="photo" src="photo_two.jpg" alt="two"> 
    <img class="photo" src="photo_three.jpg" alt="three"> 
    <img class="photo" src="photo_four.jpg" alt="four"> 
    <img class="photo" src="photo_five.jpg" alt="five"> 
    </div> 


</body> 

+0

你的鏈接,jQuery的爲m以'http:'作爲前綴。 –

+0

哦不工作我認爲你的意思是點擊事件是由mouseOvers觸發的? – Rooster

+2

@TravisJ不需要。推薦使用無協議的URI – Phil

回答

6

從class和id刪除空格,用下劃線代替它們(或連字符,或任何你想要的)。

例如:

<button id="Hide_All_Images">Hide All Images</button> 

和:

$("#Hide_All_Images").click(function(){ 

空間使用$函數時實際上意味着什麼。 $("#Hide All Images")表示找到一個標籤內<All>標籤內的東西與編號Hide

+0

...或者其他任何非空白字符 – Phil

+2

不要忘記在jQuery選擇器上更改它們! – Lunfel

+0

菲爾,沒有運氣與變化......我想知道如果也許我「錯碼」的東西。如果一個人工作,我會很高興。我至少能夠確定我出錯的地方。 – user3321167

0
  1. 您需要關閉您的圖像元素

    <img class="photo" src="photo_one.jpg" alt="one" /> 
    
  2. 元素名稱不應包含空格

    <button id="Hide-All-Images">Hide All Images</button> 
    
    $('#Hide-All-Images').click(function(){ 
        $("img").hide("fast"); 
    }); 
    
  3. 固定here

+0

不錯!謝謝你。我也能夠使它在JSFiddle上工作,但它仍然不起作用在我的頁面上。 – user3321167

+0

我能夠通過將jQuery從谷歌版本更新到靜態版本來修復它。我如何獲得照片左右移動? – user3321167

+0

不知道我明白你想通過轉移他們來完成什麼。你在找這樣的東西嗎? HTTP://計算器。com/questions/4229422/jquery-slideright-effect – millman

相關問題