This time I will bring you what are the built-in objects of js, what are the precautions when using js built-in objects, the following is a practical case, let's take a look.
Js built-in objects and browser objects
1. String object:
String object is used to process existing strings
Strings can Use double quotes or single quotes
1) indexOf() method: Find the string in the string (returns the position again, without returning -1)
2) match() method: content Match (with output string, no null returned)
3) replace() method: content replacement (two parameters)
4) toUpperCase()/toLowerCase(): string size Write conversion
5) split(): Convert string to array (commonly used)
6) Attributes: length, prototype, constructor
7) Method: charAt() , charCodeAt(), concat(), fromCharCode(), lastIndexOf(), search(), slice(), substring(), substr(), valueOf()
2, Date object: used for processing Date and time
1) Get the date of the day: new Date()
2) Common methods:
getFullYear():获得年份 getTime():获取毫秒 setFullYear():设置具体的日期(年月日) getDay():获取星期
3) Clock example:
Clock Example
function startTime(){ var today=new Date(); var h=today.getHours(); var m=today.getMinutes(); var s=today.getSeconds(); m=checkTime(m); s=checkTime(s); document.getElementById("timetxt").innerHTML=h+":"+m+":"+s; t=setTimeout(function(){ startTime(); },1000); } function checkTime(i){ if(i<10){ i="0"+i; } return i; }
3. Array object: Use separate variable names to store a series of values
Common methods:
1) concat(): merge arrays
2) sort(): Sort
升序:sort(function(a,b){ return a-b;}) 降序:ort(function(a,b){ return b-a;})
3) push(): Append elements at the end
4) reverse(): Flip array elements
4, math () Object: Perform common arithmetic tasks
Common methods:
1)round():四舍五入 2)random():0~1之间的随机数 3)max():返回最高值 4)min():返回最低值 5)abs():返回绝对值 5、浏览器对象
The Window object is the core of the BOM, the window object Refers to the current browser window. All javascript global objects, functions and variables automatically become members of the window object.
Global variables are attributes of the window object.
Global functions are window Object methods
HTML DOM document is also one of the attributes of the window object
1) Window size (excluding scroll bars)
Window.innerHeight-浏览器窗口的内部高度 Window.innerWidth-浏览器窗口的内部宽度
2) Window method
Window.open()-打开新窗口( Window.close()-关闭当前窗口
2, timer
1) Timing event: function executed after setting the time interval
2) Timing method:
setInterval()-间隔指定毫秒数不断地执行指定的代码 clearInterval()-停止setInterval()方法 setTimeout()-暂停指定的毫秒数后执行指定的代码 clearTimeout()-用于停止setTimeout()方法
3, History object : window.history object contains a collection of browser history URLs
history method:
1)history.back()-与在浏览器点击后退按钮相同 2)history.forward()-与在浏览器中点击按钮向前相同 3)History.go()-进入历史中的某个页面
4, Location object : used by window.location object To obtain the address (URL) of the current page and redirect the browser to the new page
Location对象的属性: location.hostname返回web主机的域名 location.pathname返回当前页面的路径文件名 location.port返回web主机的端口 location.protocol返回所使用的web协议(http:/或https:/) location.href属性返回当前页面的URL location.assign()方法加载新的文档
5, Screen object:
Window.screen对象包含有关用户屏幕的信息
Attribute:
Screen.availWidth-可用的屏幕宽度 Screen.availHeight-可用的屏幕高度 Screen.Height-屏幕高度 Screen.Width-屏幕宽度
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
JavaScript code to animate text
##Get the maximum width or height of a group of elements JavaScript Code
Detailed explanation of Event Loop of Node.js
Detailed explanation of JavaScript timer
The above is the detailed content of What are the built-in objects of js?. For more information, please follow other related articles on the PHP Chinese website!