2013-08-21 54 views
0

當單擊第一個複選框時,jQuery不滑動。我相信這是正確的語法,但我不確定。我曾在多個瀏覽器中查看它,甚至將它上傳到網站。但都無濟於事。我的代碼有什麼問題?jQuery滑動不正確

<!DOCTYPE html> 
<html> 
    <title>Test</title> 
<head><script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>     </script> 
    <script>$(document).ready(function(){ 
    $('#test1').click(function(){ 
     if ($(this).attr('checked')) { 
     $('#test12').slideUp('fast'); 
     } else { 
     $('#test12').slideDown('fast'); 
     } 
    }); 
    }); 
    </script> 

    </head> 
    <body> 
    <h1>form test</h1> 
    <span><input id="test1" type="checkbox">Hello<br></span> 
    <span><input id="test12" type="checkbox">Yo</span> 
    </body> 
    </html> 

回答

0

試試這個(V1.6 +)

if ($(this).attr('checked') == "checked") 

(預-1.6)..你的病情有效

if ($(this).attr('checked'))