script和body順序問(wèn)題
<!DOCTYPE html>
<html>
? ? <head>
? ? ? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
? ? <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
? ? ? ? <title>挑戰(zhàn)題</title>
? ? </head>
? ? <script type="text/javascript">
? ? ? ?$('a').click(function(){
? ? ? ? if($(this).html()==='更多'){
? ? ? ? ? $('.hidden').show();
? ? ? ? ? $(this).html("簡(jiǎn)化");
? ? ? ? }else{
? ? ? ? ? $('.hidden').hide();
? ? ? ? ? $(this).html("更多");
? ? ? ? }
? ? });
? ? </script>
? ? <body>
? ? ? ? <ul>
? ? ? ? ? ? <li></li>
? ? ? ? ? ? <li></li>
? ? ? ? ? ? <li></li>
? ? ? ? ? ? <li></li>
? ? ? ? ? ? <li></li>
? ? ? ? ? ? <li style="display:none" class="hidden"></li>
? ? ? ? ? ? <li style="display:none" class="hidden"></li>
? ? ? ? ? ? <a href="#">更多</a>
? ? ? ? </ul>
? ? </body>
? ??
</html>
請(qǐng)問(wèn)為什么上面這個(gè)代碼運(yùn)行沒(méi)反應(yīng),但是把script放到body之后就可以用了呢
2016-03-29
script放在body 或head 里面都行 你沒(méi)放在這兩者里面