Home >Web Front-end >HTML Tutorial >How to put the script in the page? _html/css_WEB-ITnose

How to put the script in the page? _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:04:421177browse


How to write text using JS script, here is a simple example:

============== ================================
Script code:


===== =========================================
Effect: This is red Words
==============================================
javascript and java are different. Java is an object-oriented programming language developed by SUN. It can be used to write independent java programs, or to write small programs called java applet. It is mainly aimed at professional programmers and is not used by ordinary users. , and generally you can’t see its source code
. Among them, java applet is closely related to homepage production. Its source code can only be executed after being compiled. When using it, you need to insert the applet code into HTML and load it through the browser for execution. Because it takes a long time to load, if there are too many java applet programs in the web page, the page download will be very slow. In this way, your visitors
may leave without too much patience waiting for the page to be fully displayed. What we are talking about here is javascript. You can think of it as a "relative" of java. It is actually a scripting language and is text-based, so we can see its source code, which is very It is easy to learn and understand. People with a little programming experience can quickly change and modify its source code to adapt to their own pages. It is a true scripting language for ordinary users. JavaScript script code
is generally inserted into the or area of ​​HTML. When the browser browses the page with JS script, it will be executed and produce an "interactive" dynamic page effect, which is very fast
Very fast. Nowadays, all well-made websites without exception use JavaScript technology to a greater or lesser extent.

It should be noted that the javascript script must be supported by the browser. If the browser does not support javascript or the browser's javascript option is not
turned on, it will not be executed. Taking the IE browser as an example, the way to turn on javascript is to allow java to run in "View-Options-Advanced".

How to write javascript?


First of all, javascript is not HTML. It is a piece of text in HTML. The syntax of HTML is not very strict. In fact, it is very loose. For example, if you add a certain number of spaces between words

or between paragraphs, it does not make much difference to HTML. This is why most HTML languages ​​do not have to Written on the same line, writing

on the same line makes no difference to HTML.

The grammatical rules of JavaScript are much stricter. If you write the above example like this: document.write("This is the red
word
"), that is, if you break the line, an error will occur during execution (error The prompt is: invalid ending). This should be noted.

Another question is: Is javascript case sensitive? The answer is: YES


The first line of javascript should be: .

Look at the above example again and explain it a little:

document.write("This is the red word") In this sentence, document is an "existing object" and write is the "method" implemented

. So the script understands how to use the object to write something, and what is written in the brackets is what you want to write, and you can use standard HTML syntax. Note:

Single quotes must be used inside double quotes to match. Otherwise, the script will run incorrectly.

============================================== =======
Review:
(1)

This is red text This is blue text


Source code:

(2)
This is a red word

This is a blue word

Source code:

:- You need to be able to write D on the same line and on new lines!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn