Home >Web Front-end >HTML Tutorial >How to put the script in the page? _html/css_WEB-ITnose
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
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
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.
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)
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!