JavaScript statements
JavaScript statement sends a command to the browser. The purpose of a statement is to tell the browser what to do.
document.getElementById uses
Syntax: oElement = document .getElementById (sID)
Parameters: sID--required options. String.
Return value: oElemen--Object (Element).
Description: Get the object based on the specified id attribute value. Returns a reference to the first object whose id attribute value is equal to sID. If the corresponding object is a group of objects, the first object in the group is returned. If there is no matching object, return null .
Note: document.getElementById(" ") gets an object. Use alert to display "object" instead of a specific value. It has attributes such as value and length. Add .value to get is the specific value!
Details:
① document.getElementById sometimes captures name and lets go of id. It is said to be a BUG of IE
② GetElementbyId in javascript is used
in the web page The element must have an id attribute before it can be obtained through this method, such as
③There are two main ways to obtain html tags, one is Through the ID value, one is through the name attribute (the name attribute is mainly used for the input tag in the form.)
Note:
document.getElementById(" " ) What you get is an object. Use alert to display the
"object" instead of a specific value. It has attributes such as value and length. Add .value to get the
It’s a specific value!
php中文网(php.cn) 你好 summer
Semicolon ;
Semicolon is used to separate JavaScript statements.
Usually we add a semicolon at the end of each executable statement.
Another use of semicolons is to write multiple statements on one line.
a = 5;
b = 6;
c = a + b;
JavaScript Code
JavaScript 代码是 JavaScript 语句的序列。 浏览器按照编写顺序依次执行每条语句。 本例向网页输出一个标题和两个段落:php中文网(php.cn) 一句问候
你最近过得怎么样?
JavaScript Code Blocks
JavaScript can be combined in batches.
A code block starts with a left curly brace and ends with a right curly brace.
The function of a code block is to execute a sequence of statements together.
This example outputs a title and two paragraphs to the web page:
php中文网(php.cn) 替代
覆盖
JavaScript statement identifier
JavaScript statements usually start with a statement The identifier starts with and executes the statement.
Statement identifiers are reserved keywords and cannot be used as variable names.
The following table lists JavaScript statement identifiers (keywords):
StatementDescription
##break is used to break out of the loop. catch statement block, execute the catch statement block when an error occurs during the try statement block. . continue Skip an iteration in the loop. do... while Execute a statement block and continue executing the statement block when the conditional statement is true. for When the conditional statement is true, you can execute the code block a specified number of times. for ... in is used to traverse the properties of the array or object (loop through the properties of the array or object).#function Define a function
if ... else Used to perform different actions based on different conditions.
return Exit function
switch Used based on Different conditions perform different actions.
throw Throws (generates) an error.
try Implements error handling and is used with catch.
var declares a variable.
while When the conditional statement is true, execute the statement block
##JavaScript is case sensitive.
JavaScript is case-sensitive.
When writing JavaScript statements, please pay attention to whether the case switching key is turned off.
The functions getElementById and getElementbyID are different.
Similarly, variables myVariable and MyVariable are also different.
Spaces
JavaScript will ignore extra spaces. You can add spaces to your script to make it more readable. The following two lines of code are equivalent:
var person="Hege";
var person = "Hege";
Wrap lines of code
You can wrap lines of code using backslashes in text strings. The following example will display correctly:
document.write("Hello\
world!");
However, you cannot wrap lines like this :
document.write \
("Hello world!");
##
- Course Recommendations
- Courseware download
IntermediateFront-end Vue3 actual combat [handwritten vue project]
2857 people are watchingElementaryAPIPOST tutorial [Popularization of technical concepts related to network communication]
1795 people are watchingIntermediateIssue 22_Comprehensive actual combat
5521 people are watchingElementaryIssue 22_PHP Programming
5172 people are watchingElementaryIssue 22_Front-end development
8713 people are watchingIntermediateBig data (MySQL) video tutorial full version
4525 people are watchingElementaryGo language tutorial-full of practical information and no nonsense
2794 people are watchingElementaryGO Language Core Programming Course
2814 people are watchingIntermediateJS advanced and BootStrap learning
2563 people are watchingIntermediateSQL optimization and troubleshooting (MySQL version)
3374 people are watchingIntermediateRedis+MySQL database interview tutorial
2963 people are watchingElementaryDeliver food or learn programming?
5708 people are watching
Students who have watched this course are also learning
- Let's briefly talk about starting a business in PHP
- Quick introduction to web front-end development
- Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
- Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
- Login verification and classic message board
- Computer network knowledge collection
- Quick Start Node.JS Full Version
- The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
- Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
- About us Disclaimer Sitemap
- php.cn:Public welfare online PHP training,Help PHP learners grow quickly!