2014-02-17 47 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

相关问题