我被这个javascript/jquery代码卡住了

I am stuck with this javascript/jquery code

本文关键字:代码 jquery javascript      更新时间:2023-09-26

http://jsfiddle.net/YtJcL/

下面是jsfiddle.net 的代码

  $(".scroll").click(function(event){
     event.preventDefault();
     //calculate destination place
     var dest=0;
     if($(this.hash).offset().top > $(document).height()-$(window).height()){
          dest=$(document).height()-$(window).height();
     }else{
          dest=$(this.hash).offset().top;
     }
     //go to destination
     $('html,body').animate({scrollTop:dest}, 1000,'swing');
   });

问题是,在JSFiddle上,代码运行良好,没有任何问题。但是,当我尝试将它插入文本编辑器并运行它时,开发人员工具会发出警告,指出"top"是未定义的——但它在JSFiddle中运行得非常好。

有人知道为什么吗?

::编辑::这是中的内容

    <head>
     <script src="ajax.googleapis.com/ajax/libs/jquery-1.11.0.js"></script>
     <script src="bootstrap.min.js"></script>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
   <meta name="author" content="">
    <link rel="shortcut icon" href="../../assets/ico/favicon.ico">
    <script type="text/javascript" src="app.js"></script>
      <title>M Y | Portfolio</title>
      <!-- Bootstrap core CSS -->
      <link href="bootstrap.min.css" rel="stylesheet">
       <link href="carousel.css" rel="stylesheet">
       <!-- Custom styles for this template -->
      <link href="jumbotron.css" rel="stylesheet">
    </head>

尝试单击引发"top"is undefined"错误的链接,检查它并检查其href属性是否已定义且不为空。