JavaScript event, string, operators, comparison operators, and logical operators

1, JavaScript events

Events can be used to handle form validation, user input, user behavior and browser actions:

页面加载时触发事件
页面关闭时触发事件
用户点击按钮执行动作
验证用户输入内容的合法性
等等 ...

JavaScript event code can be executed using a variety of methods:

HTML 事件属性可以直接执行 JavaScript 代码
HTML 事件属性可以调用 JavaScript 函数
你可以为 HTML 元素指定自己的事件处理程序
你可以阻止事件的发生。
等等 ...

2, JavaScript string

The string can store a series of characters, such as "John Doe".

String can be inserted into any character in quotation marks. You can use single or double quotes:
Example
var carname = "Volvo the XC60";
var = carname 'Volvo the XC60';

2.1, you can use the index to access the location of each character in the string:

Examples
var character = carname [7];

The index of the string starting from 0, which means that the first character index value of [0], the second is [1], and so on.

2.2, string length

The length of the string can be calculated using the built-in property length:
Example
var TXT = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var txt.length = SLN;

3, JavaScript operator

Operator = to assign.

Value for the + operator.

Operator = to a JavaScript variable.

Arithmetic operator + is used to add value.
Here Insert Picture Description
Here Insert Picture Description

3.1, for the string operator +

...... + operator used to add text or string variable (connected).
= the txt1 "A Very What";
txt2 = "Nice Day";
txt3 = + txt2 the txt1;

txt3 calculation results are as follows:
What verynice Day A

3.2, strings of numbers and adding

Two numbers together, and returns the digital addition, if the digital sum string, the string returns,
X + =. 5. 5;
Y = ". 5" +5;
Z = "the Hello" +5;

x, y, and z as output:
10
55
Hello5

4, JavaScript comparison and logical operators

For comparison and logical operators test true or false.

4.1, comparison operators

Comparison operator in a logical statement to determine the variable or values ​​are equal.
Here Insert Picture Description

4.2, logical operators

Logical operators for determining the logical connection between the variable or value.

Given x = 6 and y = 3, the following table explains the logical operators:
Here Insert Picture Description

4.3, conditional operator

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_43731793/article/details/92383815