2017-05-02 22 views
-1

私は狂っています...スクリプトにエラーがありますが、私はそれを見つけられず、奇妙な、またエクスプローラのデバッグが見つかりません!デバッグでエラーが見つかりません...奇妙な

私はエクササイズでそれをたくさん試しましたが、私はそれを見つけることができません。あなたは、構文エラーを持っている

<script src="../_js/jquery.min.js"></script> 
 
<script> 
 
$(document).ready(function() { 
 
\t \t 
 
$('#gallery img').each(function(i) { 
 
\t var imgFile = $(this).attr('src'); 
 
\t var preloadImage = new Image(); 
 
\t var imgExt = /(\.\w{3,4}$)/; 
 
\t preloadImage.src = imgFile.replace(imgExt,'_h$1'); 
 
\t \t 
 
\t $(this).hover(
 
\t \t function() { 
 
\t \t \t $(this).attr('src', preloadImage.src); 
 
\t \t }, 
 
\t \t function() { 
 
\t \t var currentSource=$(this).attr('src'); 
 
\t \t \t $(this).attr('src', imgFile); 
 
\t }); // end hover 
 
}); // end each 
 
\t 
 
$('#gallery a').click(function(evt){ 
 
\t evt.preventDefault(); 
 
\t var imgPath = $(this).attr('href'); 
 

 
var oldImage = $('#photo img'); 
 
var newImage = $('<img src"' + imgPath +'">'); 
 
newImage.hide(); 
 
$('#photo').prepend(newImage); 
 
newImage.fadeIn(1000); 
 
oldImage.fadeOut(1000,function(){ 
 
\t $(this).remove(); 
 
}); //end fadeout 
 
});// end click 
 
$('#gallery a:first').click(); 
 

 
}); // end ready 
 
</script>
<style> 
 
#gallery { 
 
\t float: left; 
 
\t width: 90px; 
 
\t margin-right: 30px; 
 
\t margin-left: 10px; 
 
\t border-right: white 1px dotted; 
 
} 
 
#gallery img { 
 
\t display: inline-block; 
 
\t margin: 0 0 10px 0; 
 
\t border: 1px solid rgb(0,0,0); 
 
} 
 
#photo { 
 
\t margin-left: 150px; 
 
\t position: relative; 
 
} 
 
#photo img { 
 
\t position: absolute; 
 
} 
 
</style>
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<meta charset="UTF-8"> 
 
<title>Rollover Images</title> 
 
<link href="../_css/site.css" rel="stylesheet"> 
 
</head> 
 
<body> 
 
<div class="wrapper"> 
 
\t <header> 
 
    JAVASCRIPT <span class="amp">&amp;</span> jQUERY: THE&nbsp;MISSING&nbsp;MANUAL 
 
\t </header> 
 
\t <div class="content"> 
 
\t \t <div class="main"> 
 
\t \t \t <h1>Slideshow</h1> 
 
\t \t \t <div id="gallery"> <a href="../_images/large/slide1.jpg"><img src="../_images/small/slide1.jpg" width="70" height="70" alt="golf balls"></a> <a href="../_images/large/slide2.jpg"><img src="../_images/small/slide2.jpg" width="70" height="70" alt="rock wall"></a> <a href="../_images/large/slide3.jpg"><img src="../_images/small/slide3.jpg" width="70" height="70" alt="old course"></a> <a href="../_images/large/slide4.jpg"><img src="../_images/small/slide4.jpg" width="70" height="70" alt="tees"></a> <a href="../_images/large/slide5.jpg"><img src="../_images/small/slide5.jpg" width="70" height="70" alt="tree"></a> <a href="../_images/large/slide6.jpg"><img src="../_images/small/slide6.jpg" width="70" height="70" alt="ocean course"></a></div> 
 
\t \t \t <div id="photo"></div> 
 
\t \t </div> 
 
\t </div> 
 
\t <footer> 
 
    <p>JavaScript &amp; jQuery: The Missing Manual, 3rd Edition, by <a href="http://sawmac.com/">David McFarland</a>. Published by <a href="http://oreilly.com/">O'Reilly Media, Inc</a>.</p> 
 
\t </footer> 
 
</div> 
 
</body> 
 
</html>

+1

を=を逃したあなたのコード –

+1

をフォーマットしてください私は ''「キャッチされないでSyntaxError:予期しないトークン}」それを実行すると、私はエラーメッセージを見ることができるが、少しのでかもしれないが ' – Orangesandlemons

+1

、のコードがありません。 – Orangesandlemons

答えて

0

、私はあなたの構文エラーを修正しました。ここで は、エラーのないバージョンです:

$('#gallery a').click(function(evt){ 
evt.preventDefault(); 
var imgPath = $(this).attr('href'); 

var oldImage = $('#photo img'); 
var newImage = $('<img src"' + imgPath +'">'); 
newImage.hide(); 
$('#photo').prepend(newImage); 
newImage.fadeIn(1000); 
oldImage.fadeOut(1000,function(){ 
    $(this).remove(); 
}); //end fadeout 
});// end click 
$('#gallery a:first').click(function() { 
    console.log("something") 
}); 

あなたは良い答えをしたい場合、あなたはあなたのhtmlと予想される動作を投稿する必要があります。

編集:あなたの質問を更新した後、ここにあなたが解決策で行く:

$(document).ready(function() { 
 
    $('#gallery img').each(function() { 
 
      var imgFile = $(this).attr('src'); 
 
     var preloadImage = new Image(); 
 
     var imgExt = /(\.\w{3,4}$)/; 
 
     preloadImage.src = imgFile.replace(imgExt,'_h$1'); 
 
     $(this).hover(
 
       function() { 
 
        $(this).attr('src', preloadImage.src); 
 
       }, 
 
      function() { 
 
        $(this).attr('src', imgFile); 
 
       } 
 
      ); // end hover 
 
      }); // end each 
 
    $('#gallery a').click(function(evt) { 
 
      evt.preventDefault(); 
 
      var imgPath = $(this).attr('href'); 
 
      var oldImage = $('#photo img'); 
 
      var newImage = $('<img src="' + imgPath + '">'); 
 
      newImage.hide(); 
 
      $('#photo').prepend(newImage); 
 
      newImage.fadeIn(1000); 
 
      oldImage.fadeOut(1000,function(){ 
 
       $(this).remove(); 
 
       }); // end fadeout 
 
     }); // end click 
 
    $('#gallery a:first').click(); 
 
}); // end ready
#gallery { 
 
\t float: left; 
 
\t width: 90px; 
 
\t margin-right: 30px; 
 
\t margin-left: 10px; 
 
\t border-right: white 1px dotted; 
 
} 
 
#gallery img { 
 
\t display: inline-block; 
 
\t margin: 0 0 10px 0; 
 
\t border: 1px solid rgb(0,0,0); 
 
} 
 
#photo { 
 
\t margin-left: 150px; 
 
\t position: relative; 
 
} 
 
#photo img { 
 
\t position: absolute; 
 
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
 
<div class="wrapper"> 
 
    <header> 
 
     JAVASCRIPT <span class="amp">&amp;</span> jQUERY: THE&nbsp;MISSING&nbsp;MANUAL 
 
    </header> 
 
    <div class="content"> 
 
     <div class="main"> 
 
      <h1>Slideshow</h1> 
 
      <div id="gallery"> 
 
       <a href="https://placeholdit.imgix.net/~text?txtsize=33&txt=one&w=500&h=500"><img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=one&w=70&h=70" width="70" height="70" alt="golf balls"></a> 
 
       <a href="https://placeholdit.imgix.net/~text?txtsize=33&txt=two&w=500&h=500"><img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=two&w=70&h=70" width="70" height="70" alt="rock wall"></a> 
 
       <a href="https://placeholdit.imgix.net/~text?txtsize=33&txt=three&w=500&h=500"><img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=three&w=70&h=70" width="70" height="70" alt="old course"></a> 
 
       <a href="https://placeholdit.imgix.net/~text?txtsize=33&txt=four&w=500&h=500"><img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=four&w=70&h=70" width="70" height="70" alt="tees"></a> 
 
       <a href="https://placeholdit.imgix.net/~text?txtsize=33&txt=five&w=500&h=500"><img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=five&w=70&h=70" width="70" height="70" alt="tree"></a> 
 
       <a href="https://placeholdit.imgix.net/~text?txtsize=33&txt=six&w=500&h=500"><img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=six&w=70&h=70" width="70" height="70" alt="ocean course"></a> 
 
      </div> 
 
      <div id="photo"></div> 
 
     </div> 
 
    </div> 
 
    <footer> 
 
     <p>JavaScript &amp; jQuery: The Missing Manual, 3rd Edition, by <a href="http://sawmac.com/">David McFarland</a>. Published by 
 
      <a href="http://oreilly.com/">O'Reilly Media, Inc</a>.</p> 
 

 
    </footer> 
 
</div>

とペンへのリンク:https://codepen.io/faw/pen/MmoQRe?editors=1111

+0

あなたの提案を氾濫させて、今すぐすべてのコードを投稿しました... しかし、どこでエラーを見つけましたか? – franco

+0

あなたのコードを投稿した後、私は働いているcodepenのリンクで私の答えを更新しました –

0

// end ready部分が$(document).ready(function() {を指し、 。

あなたのコードがなければなりません:

$(document).ready(function() { 
 
    $('#gallery a').click(function(evt) { 
 
    evt.preventDefault(); 
 
    var imgPath = $(this).attr('href'); 
 

 
    var oldImage = $('#photo img'); 
 
    var newImage = $('<img src"' + imgPath + '">'); 
 
    newImage.hide(); 
 
    $('#photo').prepend(newImage); 
 
    newImage.fadeIn(1000); 
 
    oldImage.fadeOut(1000, function() { 
 
     $(this).remove(); 
 
    }); //end fadeout 
 
    }); // end click 
 
    $('#gallery a:first').click(); 
 
}); // end ready
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

0

OKを最後に、私は、エラーが、それは VAR NEWIMAGE = $( '')は、このラインがわかりました。 私はSRC後

おかげ

関連する問題