2013-02-21 8 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

相關問題