2013-02-21 32 views
-2
<!DOCTYPE html> 
<html> 
<head> 
<div id="header"> 
    <center><button type="button" onclick="JavaScript:prompt('so far sogood')"> 
    click</button></center> 
    </div> 

<style type="text/css">         
#one{width:100%; height:100px;background-color:red;} 
#two{width:100%; height:100px;background-color:green;} 
#header{width:100%; height:100px;background-color:yellow;} 
</style> 
<script type="text/javascript"> 

$(document).ready(function(
{ 
$('.one').mouseenter(function() 
{ 
$(this).fadeOut('slow'); 
}); 

$('.one').mouseleave(function() 
    { 
$(this).fadeIn('fast'); 

}); 

}); 
</script> 


</head> 
<body bgcolor="black"> 





<div id="one"><center>HELLO</center></div> 
<div id ="two">hello</div> 
</body> 

它看起来像我的问题是我的jQuery的行开始$(document)需要的地方之后。显然我在这之前没有把事情做好。我是新来的jQuery,通常我使用外部CSS网页等不同格式需要的地方

+3

如果这是你的整个脚本,我没有看到对jquery.js的引用 - 无论是本地版本还是任何地方包含的CDN版本... – ryadavilli 2013-02-21 17:28:51

回答

2

你有一个语法错误:最后一个括号准备函数声明后失踪

$(document).ready(function( {

尝试

<script type="text/javascript"> 
     $(document).ready(function() { 
      $('.one').mouseenter(function() { 
       $(this).fadeOut('slow'); 
      }); 

      $('.one').mouseleave(function() { 
       $(this).fadeIn('fast'); 

      }); 

     }); 
    </script> 

DEMO