jQuery ??
jQuery? ???? HTML ??? ??(??)?? ?? ??? ?? "??"? ??? ? ????.
jQuery ??
jQuery ??????? ??? ?? ???? ?? ?? ???? ?? ?? ?? "$"? ????? ? "$"? jQuery???. ? ? ?? ???? ??? ??? jQuery ????? ??? ??? ????? ??? ??? ??? ? ??? ?? ??? ? ????.
$(function(){}); //執(zhí)行一個匿名函數(shù)
$('#box'); //進(jìn)行執(zhí)行的ID元素選擇
$('#box').css('color','red'); //執(zhí)行函數(shù)功能
"$" ??? jQuery ??? ?????, ?, ? ??? ??? ?? ???? ??? ? ????.
jQuery(function(){});
jQuery('#box');
jQuery('#box').css('color','red');
Instance
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>表格</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js" type="text/javascript"></script> <script> $(function(){ $('#box').css('color','red'); }); // alert($===jQuery); </script> </head> <body> <div id="box">jQuery語法</div> </body> </html>
jQuery ?? ??
$(function(){})? ??????. ?? ???? ? ??? ??? ?? ?????.
??? jQuery ????? ??? body ???? ?? ???? ?????. JavaScript ??? ???? ?? ?? ???? ??? ??? ??? ???? ???. ??? ???
????? ?? ? ????.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>表格</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js" type="text/javascript"></script> <script> $('#box').css('color','red'); </script> </head> <body> <div id="box">jQuery語法</div> </body> </html>
?? JavaScript? ??? ??????.
window.onload=function(){}; //JavaScript等待加載
jQuery? ??? ??????.
$(document).ready(function(){}); //jQuery等待加載
? ??? ???:
1. ?? ??
window.onload: ??? ??? ???? ?? ????? ??(??? ??)? ??? ???? ???.
$(document).ready(function(){}): ??? ??? ???? ?? ????? DOM ??? ??? ??? ?????. ??? ? ????
2. ?? ??
window.onload? ? ?? ??? ? ??? ? ?? ?? ? ? ?? ??? ???? ???
$ (document ).ready(function(){}): ? ?? ???? ????? ????.
window.onload None
$(document).ready(function(){ }) $(?? (){});?? ????????? window.onload? ?? ???? ??? ?? ????. ???? JS ??? ???? ?? ??? ?? ? ??? ??? ??? ???? ?? ?????. ???? ??? ??? ???? ??? ?????. ???? ???? ??? ??? ?????. ?? ???? ?? JS ??? ??(?: ?? ???? ?? ?)? ?? ??? ????? ?????.