JSON

ÇáËÉѧϰJavaScriptÈý£ºJavaScriptÓëHTMLµÄ½áºÏ

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2015-11-21 13:15 ÎÒÒªÆÀÂÛ( )

ÇáËÉѧϰJavaScriptÈý£ºJavaScriptÓëHTMLµÄ½áºÏ

       HTMLÖеÄJavaScript½Å±¾±ØÐëλÓÚ<script>Óë</script>±êÇ©Ö®¼ä£¬JavaScript½Å±¾¿É±»·ÅÖÃÔÚHTMLÒ³ÃæµÄ

<body>±êÇ©ºÍ<head>±êÇ©ÖУ¬ÕâÖÖÊÓÇé¿ö¶ø¶¨£¬Ò»°ã·ÅÔÚ<head>±êÇ©ÄÚ¡£

       Ò»<script> ±êÇ©

      ÈçÐèÔÚHTMLÒ³ÃæÖвåÈëJavaScript½Å±¾£¬ÇëʹÓÃ<script>±êÇ©¡£<script>ºÍ</script>»á¸æËßJavaScriptÔںδ¦¿ªÊ¼

ºÍ½áÊø¡£<script>ºÍ</script>Ö®¼äµÄ´úÂëÐаüº¬ÁËJavaScript£º

<span style="font-size:18px;"><script type="text/javascript"> alert("»¶Ó­À´µ½JavaScriptÊÀ½ç£¡£¡£¡"); </script></span>       ÄúÎÞÐèÀí½âÉÏÃæµÄ´úÂë¡£Ö»ÐèÃ÷°×£¬ä¯ÀÀÆ÷»á½âÊͲ¢Ö´ÐÐλÓÚ <script> ºÍ </script> Ö®¼äµÄ JavaScript¡£ÄÇЩÀÏ

ÒÔ¼°HTML5ÖеÄĬÈϽű¾ÓïÑÔ¡£¼øÓÚ¸Õ¸ÕѧϰJavaScriptÓïÑԵĿÉÒÔʹÓã¡

       ¶þ<body>ÖеÄJavaScript

       ÔÚ±¾ÀýÖУ¬JavaScript»áÔÚÒ³Ãæ¼ÓÔØʱÏòHTMLµÄ<body>дÎı¾£º

       ÊµÀý´úÂ룺

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JavaScript½Å±¾ÓïÑÔ</title> > </head> <body> <p> JavaScript Äܹ»Ö±½ÓдÈë HTML Êä³öÁ÷ÖУº </p> <script type="text/javascript"> document.write("<h1>This is a heading</h1>"); document.write("<p>This is a paragraph.</p>"); </script> <p> ÄúÖ»ÄÜÔÚ HTML Êä³öÁ÷ÖÐʹÓà <strong>document.write</strong>¡£ Èç¹ûÄúÔÚÎĵµÒѼÓÔغóʹÓÃËü£¨±ÈÈçÔÚº¯ÊýÖУ©£¬»á¸²¸ÇÕû¸öÎĵµ¡£ </p> </body> </html>       ÎÒÃÇÏȲ»¹ÜJavaScript´úÂëÔõôдºÍÔõôÔËÐУ¬ÏÈÀ´¿´ÔËÐнá¹û£º


       ÈýJavaScript º¯ÊýºÍʼþ

       ÉÏÃæÀý×ÓÖÐµÄ JavaScript Óï¾ä£¬»áÔÚÒ³Ãæ¼ÓÔØʱִÐС£Í¨³££¬ÎÒÃÇÐèÒªÔÚij¸öʼþ·¢ÉúʱִÐдúÂ룬±ÈÈçµ±Óû§

µã»÷°´Å¥Ê±¡£Èç¹ûÎÒÃÇ°Ñ JavaScript ´úÂë·ÅÈ뺯ÊýÖУ¬¾Í¿ÉÒÔÔÚʼþ·¢Éúʱµ÷Óøú¯Êý¡£

       ËÄ<head>»ò<body>ÖеÄJavaScript

    Äú¿ÉÒÔÔÚ HTML ÎĵµÖзÅÈë²»ÏÞÊýÁ¿µÄ½Å±¾¡£½Å±¾¿ÉλÓÚ HTML µÄ <body> »ò <head> ²¿·ÖÖУ¬»òÕßͬʱ´æÔÚÓÚ

Á½¸ö²¿·ÖÖС£Í¨³£µÄ×ö·¨ÊǰѺ¯Êý·ÅÈë <head> ²¿·ÖÖУ¬»òÕß·ÅÔÚÒ³Ãæµ×²¿¡£ÕâÑù¾Í¿ÉÒÔ°ÑËüÃÇ°²Öõ½Í¬Ò»´¦Î»Öã¬

²»»á¸ÉÈÅÒ³ÃæµÄÄÚÈÝ¡£

       Îå<head>ÖеÄJavaScriptº¯Êý

       ÔÚ±¾ÀýÖУ¬ÎÒÃÇ°ÑÒ»¸öJavaScriptº¯Êý·ÅÖõ½HTMLÒ³ÃæµÄ<head>²¿·Ö¡£¸Ãº¯Êý»áÔÚµã»÷°´Å¥Ê±±»µ÷Óãº

       ÊµÀý´úÂ룺

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JavaScript½Å±¾ÓïÑÔ</title> <script type="text/javascript"> function myFunction() { document.getElementById("demo").innerHTML="My First JavaScript Function"; } </script> </head> <body> <h1>My Web Page</h1> <p id="demo">A Paragraph.</p> <button type="button" onclick="myFunction()">µã»÷ÕâÀï</button> </body> </html>        ÔËÐеĽá¹ûΪ£º


       µã»÷°´Å¥ºóµÄЧ¹ûΪ£º


       Áù<body>ÖеÄJavaScrip º¯Êý

       ÔÚ±¾ÀýÖУ¬ÎÒÃÇ°ÑÒ»¸öJavaScriptº¯Êý·ÅÖõ½HTMLÒ³ÃæµÄ<body>²¿·Ö¡£¸Ãº¯Êý»áÔÚµã»÷°´Å¥Ê±±»µ÷Óãº

       ÊµÀý´úÂ룺

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JavaScript½Å±¾ÓïÑÔ</title> </head> <body> <h1>My First Web Page</h1> <p id="demo">A Paragraph.</p> <button type="button" onclick="myFunction()">µã»÷ÕâÀï</button> <script type="text/javascript"> function myFunction() { document.getElementById("demo").innerHTML="My First JavaScript Function"; } </script> </body> </html>

       ÔËÐеĽá¹ûÓëÉÏÊöÎåµÄ½á¹ûÒ»Ñù£¡

       Ìáʾ£ºÎÒÃÇ°Ñ JavaScript ·Åµ½ÁËÒ³Ãæ´úÂëµÄµ×²¿£¬ÕâÑù¾Í¿ÉÒÔÈ·±£ÔÚ <p> ÔªËØ´´½¨Ö®ºóÔÙÖ´Ðнű¾¡£

       ÆßÍⲿµÄJavaScript

       ÎÒÃÇÒ²¿ÉÒ԰ѽű¾±£´æµ½ÍⲿÎļþÖС£ÍⲿÎļþͨ³£°üº¬±»¶à¸öÍøҳʹÓõĴúÂë¡£Íⲿ JavaScript ÎļþµÄÎļþÀ©

Õ¹ÃûÊÇ .js¡£ÈçÐèʹÓÃÍⲿÎļþ£¬ÇëÔÚ <script> ±êÇ©µÄ "src" ÊôÐÔÖÐÉèÖøà .js Îļþ£¬Èç¹ûÓдóÁ¿µÄJavaScript´úÂ룬ÎÒ

ÃÇÌᳫʹÓÃÍⲿµÄJavaScript·½Ê½£¬Ò»°ãÎÒÃÇÒ²²ÉÓ÷ÖÀëµÄ·½Ê½Á¬½Óµ½HTMLÎĵµÖС£

       ÊµÀý

       HTML´úÂ룺

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • JavaScriptת»»Óë½âÎöJSON·½·¨ÊµÀýÏê½âµÚ1/2Ò³

    JavaScriptת»»Óë½âÎöJSON·½·¨ÊµÀýÏê½âµÚ1/2Ò³

    2016-02-10 21:25

  • JSON Schema ÄÇЩʶù£º»ù±¾¸ÅÄî

    JSON Schema ÄÇЩʶù£º»ù±¾¸ÅÄî

    2016-01-31 10:32

  • δÀ´±à³ÌµÄ9´ó²ÂÏ룺JavaScript²»±ØÇ××Ô±àд

    δÀ´±à³ÌµÄ9´ó²ÂÏ룺JavaScript²»±ØÇ××Ô±àд

    2016-01-30 13:01

  • Objective-CÓëJavaScript½»»¥µÄÄÇЩÊÂ

    Objective-CÓëJavaScript½»»¥µÄÄÇЩÊÂ

    2016-01-30 13:00

ÍøÓѵãÆÀ
Ð