[英]jQuery not working outside of JS Bin
I'm having an odd issue. 我有一个奇怪的问题。 I have a simple page that uses jQuery and CSS, and even though I have the code to embed jQuery via Google API, the javascript isn't working on either my local machine or my web server.
我有一个使用jQuery和CSS的简单页面,即使我具有通过Google API嵌入jQuery的代码,该javascript也无法在我的本地计算机或Web服务器上运行。
It works fine on JS Bin ( http://jsbin.com/oyimes/2/edit ), just not when I put it all together in Dreamweaver. 它可以在JS Bin( http://jsbin.com/oyimes/2/edit )上正常工作,而当我将它们全部整合到Dreamweaver中时则不能。 Here's my code:
这是我的代码:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
...
JavaScript: JavaScript的:
// JavaScript Document
$('.subtitles').hide();
$('#title1').click(function(){
$('#title1subtitles').slideToggle(750,function(){
$('#title1subtitles li div').animate({width:'100%'}, 1500);
});
});
$('#title3').click(function(){
$('#title3subtitles').slideToggle(400,function(){
$('#title3subtitles li div').animate({width:'100%'}, 1500);
});
});
$('#title4').click(function(){
$('#title4subtitles').slideToggle(400,function(){
$('#title4subtitles li div').animate({width:'100%'}, 1500);
});
});
You need to wrap your js code in $(document).ready(function()
您需要将js代码包装在
$(document).ready(function()
$(document).ready(function(){
$('.subtitles').hide();
$('#title1').click(function(){
$('#title1subtitles').slideToggle(750,function(){
$('#title1subtitles li div').animate({width:'100%'}, 1500);
});
});
$('#title3').click(function(){
$('#title3subtitles').slideToggle(400,function(){
$('#title3subtitles li div').animate({width:'100%'}, 1500);
});
});
$('#title4').click(function(){
$('#title4subtitles').slideToggle(400,function(){
$('#title4subtitles li div').animate({width:'100%'}, 1500);
});
});
});
The reason it is working in jsbin is, that it adds the $(document).ready(function(){
for you 它在jsbin中工作的原因是,它为您添加了
$(document).ready(function(){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.