tailieunhanh - Tự học HTML và CSS trong 1 giờ - part 45

Tham khảo tài liệu 'tự học html và css trong 1 giờ - part 45', công nghệ thông tin, đồ họa - thiết kế - flash phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 416 LESSON 14 Introducing JavaScript Output FIGURE The results of a simple script. The page includes a single line of JavaScript which writes the Printed by JavaScript on the page. First of all that text is printed between the other two paragraphs on the page demonstrating that the browser executed the JavaScript as soon as it got to it. As you can see adds text to the page source. What this code does is call the write method of the document object which takes a single parameter the text to be added to the page. For now it s important to know that the document object is a representation of the current page that is accessible by JavaScript. A method represents a type of message that can be sent to an object the write method tells the document object to add some text to the page. I talk a lot more about the other objects that the browser provides to JavaScript a bit later. Before that I discuss the argument that I passed to a bit more. The bit of text that I passed to the method in the previous example is called a string in the vocabulary of programming. When you pass a value to a method it s called an argument. So you say that expects a string argument which it then adds to the source of the document. JavaScript is a loosely typed language so even though expects a string you don t actually have to give a string to work with. You can give it any type of data you want and it will do its best to turn it into a string and print it on the page. So for example you can give it a number script type text javascript 500 script It will convert the number to a string and print it on the page. Or you can even pass it an object like this script type text javascript charset utf-8 document script The results are in Figure . Download from The JavaScript Language 417 Output FIGURE Attempting to write an object to the page. That s the string .