Home Web Front-end JS Tutorial Summary of Javascript object attribute methods_javascript skills

Summary of Javascript object attribute methods_javascript skills

May 16, 2016 pm 05:13 PM
javascript Object properties

数组(Array):系列元素的有序集合

属性:

length:用于获取数组元素的个数,既最大下标加 1

方法:

sort(function):在未指定排序号的情况下,按照元素的字母顺序排列,如果不是字符串类型则转换成字符串,在排序;

reverse():颠倒数组中元素的顺序;

concat(array1,arrayn):用于将N个数组合并到array1数组中;

join(string):用于将数组中元素合并为字符串,string为分隔符,如省略参数,则直接合并,不加分隔;

slice(start,stop):用于返回数组中start到stop中的元素,如果参数为负,则表示倒数start或stop个元素;

toString():将数组所有元素返回一个字符串,其间用逗号分隔;

字符串(string)

属性:

length:用于返回字符串的长度,用法与数组一样;

方法:

anchor():该方法创建如同HTML中的anchor一样的标记,格式 ,通过下列方法访问 string.anchor(chorName)

toUpperCase():将字符串转换成大写;

toLowerCase():将字符串转换成小写;

indexOf(a,b):从第 b 个字符查找字符 a 在字符串中出现的位置并返回,如果 b 省略,则默认从 0 位置查找;

chartAt(i):返回字符串中第 i 个字符;

substring(start,end):返回字符串中从 start - end 之间的全部字符(但是不返回end本身那个字符哦);

sub():将指定的字符串用下标格式显示;
 

日期(Date):详细演示见

定义方法:

a: var newdt=new Date() -->创建时间对象并赋值为当前时间;
b: var newdt=new Date(milliseconds) --> 创建时间对象,且以GTM的延迟时间来设置对象的值,单位为毫秒;
c:var newdt=new Date(string) -->使用特定的时间字符串为新创建的时间对象赋值,其格式与Date对象的parse方法匹配;
d: var newdt=new Date(年,月,日,小时,分,秒,毫秒) -->按照年,月,日,小时,分,秒,毫秒 的顺序为对象赋值;

方法:获取时间;设置时间;格式转换

A:获取时间

getDate() -----获取当前完整时间;
getYear()------获取当前的年
getMonths()----获取当前的月份
getDay()-------获取当前的日期 天
getHours()-----获取当前的小时
getMinutes()---获取当前的分钟
getSeconds()---获取当前的秒
getTime()------获取当前的时间,单位 秒
getTimeZoneOffset--获取当前的时区偏移信息

b:设置时间

对照上面的获取,把get换成 set 即可,例如 getDate() ---> setDate()

c:转换方法

toGTMString() ------转换成格林威治标准时间表达式的字符串;
toLocaleString()----转换成当地时间表达的字符串
toString()----------把时间转换成字符串
parse---------------从表示时间的字符串中读出时间
UTC-----------------返回从格林威治标准时间到指定时间的差距,单位为 毫秒


Math 数学:

属性:注意,数学对象中的属性是指读的

E (=2.7182) ------自然对数的底(具体意思,我不明白,唉,和数学密切的东西我都不明白,郁闷!)
LN10(=2.30259) ---10的自然对数;
LN2(=0.69315)-----2的自然对数;
PI(=3.1415926)----圆周率
SQRT1_2(=0.7071)--1/2的平方根
SQRT2(=1.4142)----2的平方根
LOG2E(=1.44269)---以2为底,E的对数
LOG10E(=0.43429)--以10为底E的对数

方法: 其实用得上的不多,郁闷,全部弄出来吧

sin(a) ---- 求a的正弦值
cos(a)------求a的余弦值
tan(a)------求a的正切值
asin(a)-----求a的反正弦值
atan(a)-----求a的反余弦值
exp(a)------求a的指数
log(a)------求a的自然对数
Pow(a,i)----求a的i次方(乘方)
round(a)----对a进行四舍五入运算
sqrt(a)-----求a的平方根
abs(a)------求a的绝对值
random()----取随机数
max(a,b)----取较大的数
min(a,b)----取较小的数

注意:函数的参数均是浮点类型,三角函数的参数为弧度值,而不是度
 

JavaScript的内置函数

escape() 与 unescape() :对字符串进行 编码与解码

eval(字符串):用于执行字符串所代表的运算或语句
        例如:var a=0; var str1="a+=a"; eval(str1);

parseInt() 和 parseFloat():将文本框的值转换成整数 或 浮点数

Note: parseInt() does not round the number, but trims the tail

isNaN(): The complete E text is (is not a number). As the name suggests, it is to determine whether the string is a number, such as if(isNaN("天blastpiercing series tutorial"))

Custom objects: There are two methods: initializing objects and objects defining constructors

a: initialization object

For example: Object = {Attribute 1: Value 1; Attribute 2: Value 2; ... Attribute n: Value n}. Note that each attribute value pair is separated by a semicolon;

b: Object defining constructor

For example:
function function name (attribute 1, attribute 2,... attribute N) {

this.Attribute1=attribute value 1;
this.attribute2=attribute value 2;
this.attributen=attribute valuen;

this.methodname1=functionname1;
this.methodname2=functionname2;
}

Note: The method name and function name can have the same name, but before the method calls the function, the function must have been defined, otherwise an error will occur

To create a new instance of a custom function, use the new statement.

Browser Object

Window object: He belongs to the central level, the highest level of all objects. To put it bluntly, without him, you would have nothing to play;

Properties:

closed----------used to determine whether the window is closed;
er----------stores the parent window of the window opened by the () method;
defaultstatus- --The information displayed by default in the status bar;
status----------The information currently displayed in the status bar;
Document, Location, History---very important, will be discussed in detail later, if Don’t want to wait, just look here

Method:

alert(text)-------------pops up a prompt message box
confirm(text)----------confirm message box, the parameter is confirmation Information
prompt(text,default)----pops up the input dialog box, the parameters are prompt information and default value


document object: includes each of the current web page Features, such as title URL background language modification time, etc.

Properties:

title------------Document title
lastModified-----File last modified time
URL--------------Document The corresponding page address
Cookie-----------used to create and obtain Cookie information
bgColor----------the background color of the document
fgColor-- --------The foreground color of the document
location---------Save all page address information of the document
alinkcolor-------The color of the activated link
linkcolor--------The color of the link
vlinkcolor------The color of the viewed link

Method:

write(text)---Write text or labels to the document without line breaks
writeln(text)---Write text or labels to the document with line breaks at the last character
( )----------Open a new document such as ("Address", "Window Name", "Style")
close()---------Close the current document

Location object: Contains all page address information of the current document

Properties:

protocol-----------Communication protocol
host---------------The host name of the WEB server where the page is located
port--- ------------Port number for server communication
pathname----------The path of the document on the server
hash-------- -------Anchor tag information for page jump
searce-------------Search information submitted by the page to the server
hostname------- ----Host name and port number, separated by colon
href---------------Complete URL address

Method:

assign(URL)--------Navigate the page to another address
reload-------------Refresh the page
replace(URL)- ------Use the page with the specified URL to replace the current page

History: This object includes information about previously visited URLs

Attribute: length, returns the number of URLs

The main method is go(n), through which the relative page is loaded

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

How to use insertBefore in javascript How to use insertBefore in javascript Nov 24, 2023 am 11:56 AM

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

See all articles