Now you know the basics of computer programming. Let's continue to study the Document Object Model (Document Object Model-DOM). The click relationship of the DOM starts with the window object being a Document object in each window object. We'll focus on the Document object and see how you can use it to obtain information from your users and dynamically display new information.
We have already seen an attribute of the file object - the Images array. In Lesson 3, the first image in the file can be modified by changing its src attribute.
Example:
window.document.images[0].src='some_new_picture.gif';
This command will change the first image in the document into a new image named some_new_picture.gif. In the DOM, each image in the image array is also an object. So the images[0].src instruction works like an object. It means: call the object image[0] in Image from the Image array and set its src attribute. To translate it: call the document attribute from the window, call the first image from the image array of the document, and set its src attribute to the image some_new_picture.gif.
The Image object has many other interesting properties. For example, you can let JavaScript check whether an image has been fully loaded before doing other things. However, we can only talk about these properties in future lessons. Today, we’re going to talk about feedback forms and how to use them in JavaScript.
The feedback form is part of the HTML 1.0 specification. Many people don't know much about it. Many people only think that it is only possible due to client-side CGI programming. In fact, even if you are not a CGI programmer, feedback forms provide you with a lot of functionality. JavaScript can be used to add various functionality to feedback forms. And it does not require the assistance of client CGI.
If you don’t understand how feedback forms work, please take the relevant courses in Introduction to HTML. Then start studying this lesson.
First of all, in javascript, the feedback form is also stored in an object array. You can call the first image in the image array through window.document.images[0], and you can also call the first form in the feedback form array using window.document.forms[0]. You can name the image and similarly name the feedback form. For example, if the feedback form
is programmed as follows:
You can reference the form in one of the following two ways:
var the_form = window.document.forms[0];
var the_same_form = window.document.first_form;
More often, you need to reference elements within the form, For example, the text field in the example above.
Slide your mouse over the link to see what happens.
Yes, and I know it. No!
This wonderful transformation can be achieved by changing the value of the text field.
Change the link of the text field to:
It means that the form calls the first form and sets its value to 'Clap clap!' The second line has a similar effect. This is very similar to changing the src of an image. It's just that the text field changes the value.
A similar method can be used to change the value of textareas:
Part 1 Part 2
Form code:
Its usage is the same as calling any object method: object_name.method(). The name of the text field is window.document.form_name.text_field_name, so the focus() method of the text field can be called with the following statement.
window.document.method_form.method_text.focus();
The form is also Objects; they have their own methods, properties, and event handlers. One of them is onSubmit.
The onSubmit call has the following two situations: if the user clicks the Submit button, or the user presses the Enter key in the text field, onSubmit will be triggered.
In Netscape, clicking a Submit button without result event handling usually causes the original page to be refreshed. To avoid this, you can do this:
Javascript uses return false to prevent the browser from refreshing the page. Another example is to prevent an href from redirecting to the assigned URL. For example: link sohu! will not redirect Any URL, because you set onClick to return false. The following is a form that gets information from the user. Enter something in the text field and press Enter: Who does the monkey love:
The following is the encoding of the form:
When you click Enter in the text field, the onSubmit processor is called to execute the function monkeyLove(), which will change the text value in the domain.
If there is no return false statement in the onsubmit processor, executing the function monkeyLove() will change the text field content, but since the web page content will be refreshed at the same time, the text field content will be returned to the original content. In order to prevent this phenomenon, return false must be added to onSubmit.
The following is the content of the monkeyLove() function:
function monkeyLove()
{
var who_it_is = window.document.text_entry_form.monkey_love.value;
who_it_is = 'The monkey loves ' who_it_is;
window.document.text_entry_form.monkey_love.value = who_it_is;
}
Text field and text area are two elements of the form. Others include check boxes, radio buttons and drop-down menus. First we learn about checkboxes.
The main attribute of the checkbox is: checked.
If you have a form called the_form with a checkbox named the_checkbox, you can see what happens if you click the checkbox:
var is_checked = window .document.the_form.the_checkbox.checked;
if (is_checked == true)
{
alert("Yup, it's checked!");
} else {
alert ("Nope, it's not checked.");
}
If the checkbox is checked, the checkbox attribute is true. True is a built-in data type in JavaScript, so you don't have to add quotes around true. If the checkbox is unchecked, its property is false, which is also a built-in data type.
You can also set the properties of the checkbox. The following is an example of setting the checkbox properties:
Click to check Checkbox 1
Click to uncheck Checkbox 1
Click to see the value of Checkbox 1
The following is the code :
Click to check Checkbox 1
Click to uncheck Checkbox1
Click to see the value of Checkbox 1
Note that I always add return false to the link to prevent the browser from refreshing the page and returning to the original content . The event handler for the checkbox is onClick. The onClick event handler comes into play when someone clicks on the checkbox. The following are examples of its use.
In this example, the form applies the onClick checkbox handler:
When someone clicks the checkbox, the onClick processor is activated and executes the function switchLight(). The following is the function The encoding of switchLight() (it is placed in the header of the web page):
function switchLight()
{
var the_box = window.document.form_2.check_1;
var the_switch = "" ;
if (the_box.checked == false) {
alert("Hey! Turn that back on!");
document.bgColor='black';
} else {
Alert ("THANKS!");
Document.bgcolor = 'White';
}
}
The first line:
var the_box = window .document.form_2.check_1;
Assign the checkbox object to a variable. This reduces programming length and allows objects to be passed as parameters to functions.
In the next lecture we will explain the relevant knowledge of radio buttons.

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
