//第一题 $('#container').fadeIn('slow'); //第二题 var color; $('p').hover(function(){ color = $(this).css('backgroundColor'); $(this).css('backgroundColor','yellow'); },function(){ $(this).css('backgroundColor',color); }); //第三题 $('div#container h2').click(function(){ $(this).fadeTo('slow',0.25); $(this).css({'margin-left':'20px'}); }); //或者 $('div#container h2').click(function(){ $(this).animate({ opacity:0.25, 'margin-left':'20px' },'slow'); }); //第四题 $(document).keyup(function(event){ $('#switcher').css('position','relative'); switch(event.keyCode){ case 37: $('#switcher').animate({'left':'-=20px'},'slow'); break; case 38: $('#switcher').animate({'top':'-=20px'},'slow'); break; case 39: $('#switcher').animate({'left':'+=20px'},'slow'); break; case 40: $('#switcher').animate({'top':'+=20px'},'slow'); break; } });