2016-07-26 37 views
1

我给。当我将它转移到Dreamweaver时,我似乎无法让jsfiddle代码工作?我必须错过简单的事情?它在jsfiddle中工作正常。我添加了ready函数而不是onload,但它仍然不起作用。转jsfiddle到dreamweaver

$("document").ready(function() { 
 

 
     var h1 = $('div#greeting h1'); 
 

 
     h1.hide().contents().each(function() { 
 
     var words; 
 
     if (this.nodeType === 3) { 
 
      words = this.data.split(/\s+/).map(function(w) { 
 
      return '<span>' + w + '</span>'; 
 
      }).join(''); 
 
      $(this).replaceWith(words); 
 
     } else if (this.nodeType === 1) { 
 
      $(this).html($(this).html().split(/\s+/).map(function(w) { 
 
      return '<span>' + w + '</span>'; 
 
      }).join('')); 
 
     } 
 
     }); 
 

 
     h1.find('span').hide().each(function() { 
 
     if (!$.trim(this.innerHTML)) { 
 
      $(this).remove(); 
 
     } 
 
     }); 
 

 
     $('#start').on('click', function() { 
 
     h1.show().find('span').each(function(i, e) { 
 
      h1.queue(function(next) { 
 
      $.when($(e).fadeIn(150).fadeOut(150)).done(next); 
 
      }); 
 
     }); 
 
     }); 
 
     $('#stop').on('click', function() { 
 
     h1.finish(); 
 
     }); 
 
     $('#reset').on('click', function() { 
 
     h1.finish(); 
 
     });
.box { 
 
    border: 1px solid #E38E34; 
 
    background-color: #FFE7BF; 
 
    height: 150px; 
 
    -webkit-border-radius: 1px; 
 
    -moz-border-radius: 1px; 
 
    border-radius: 1px; 
 
} 
 
#title { 
 
    margin: 5px; 
 
    border-bottom: 1px solid #E38E34; 
 
    color: #C46908; 
 
    font-weight: bold; 
 
} 
 
#message { 
 
    margin: 5px; 
 
} 
 
h1 { 
 
    font-size: 50px; 
 
    text-align: center; 
 
}
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 

 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
 

 
    <link rel="stylesheet" type="text/css" href="styles.css"> 
 

 
    <title>TedsCode</title> 
 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
 

 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
 

 
    <script type="text/javascript" src="speedread.js"></script> 
 
</head> 
 

 
<body> 
 
    <div class="box" /> 
 
    <div id="title"><span id="name">Title</span> 
 
    </div> 
 
    <div id="message" /> 
 
    <div id="greeting" /> 
 
    <input type="button" value="Read" id="start" /> 
 
    <input type="button" value="Stop" id="stop" /> 
 
    <input type="button" value="Reset" id="reset" /> 
 
    <h1><center>This is a test to see if this script displays one word at a time and functions correctly.</center></h1> 
 

 
</body> 
 

 
</html>

回答

0

您在JS哈瓦语法错误。

我对某事发表了评论:add“});”到js,并删除多余的jquery引用。

代码片断现在的工作

+0

哇, Dreamweaver应该显示错误,谢谢,它的工作很好:) – user3457159

0

我可以看到两件事情:在同一时间1.9.1和2.1.0 1,你为什么要使用两个版本的jQuery? 2,在你粘贴代码时,$(“文件”)。就绪(函数(){ 是没有正确关闭

你在控制台或网络收到任何错误?

+0

哇,它没有在Dreamweaver中显示错误,令人惊讶的是它有多简单。谢谢。 – user3457159