JavaScript Learning Notes (ii)

Source: Internet
Author: User

One, javascript placement, annotation, output tool 1, output tool A, alert (), belongs to the Global function in window.    Whatever is written, it is output as a string. B, document.write (); Output content to Web pages.
C, var vlaue=prompt ("Display content", "text box display content") value is the return value; pops up an input box to receive parameters.
 
   
  
  1. <script>
  2. alert(123);
  3. document.write(");
  4. var i=prompt("你好","请问你是?");
  5. alert(i);
  6. </script>
2, JavaScript How to place in HTML page A, <script type= "Text/javascript" language= "JavaScript" ></script> label pair form. Let the browser recognize that JavaScript starts there and ends there.        (1)type= "Text/javascript" allows the browser to recognize JavaScript language(2) can be called at any position in head or body
(3) but they are still a whole that are interconnected and interact with each other. As a whole.
b, you can call JavaScript in a hyperlink or redirect (you must start with javascript: "" to wrap it up and let the browser recognize the JavaScript codehyperlink format: "Javascript:alert (' I am a hyperlink ') 'Redirection format: "action=" Javascript:alert (' I am a form ') '
 
   
  
  1. <a href="javascript:alert(‘我是超链接‘);">链接</a>//超连接
  2. <form action="javascript:alert(‘我是表单‘)" method="post">//重定向
  3. <input type="text" name="names"/>
  4. <input type="submit" value="提交"/>
  5. </form>
C. Call after an event
format: onclick= "Javascript:alert (' I am an event ')"
 
   
  
  1. <div onclick="javascript:alert(‘我是事件‘)">我是事件</div>
        ie under the special event call, Firefox Google does not support:
 
   
  
  1. <script for="one" event="onclick">
  2. alert(我是IE特有事件);
  3. </script>
  4. <body>
  5. <div id="one">我是IE特有事件</div>
  6. </body>
D. Calling external JavaScript files
* cannot have any code in the call page <script> tag pair
* Tag pairs cannot appear in JS script
* All JS are a whole, are interconnected, affect each other
format: <script src= "file path" ></script>
 
   
  
  1. JavaScript files written in
  2. var a="你好世界"
  3. alert(a);
 
   
  
  1. <!--html页面中-->
  2. <script src="文件路径"></script>

3. CommentsA, the browser against the long
(1) <!--xxxxxxxx--> as HTML code masking
B. Normal comment
(2)//xxxxxxxx single-line comment
(3)/*xxxxxxxx*/multi-line annotation


From for notes (Wiz)

JavaScript Learning Notes (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.