JavaScript Object Summary _js Object-oriented

Source: Internet
Author: User

One day from the other day

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title>javascript object </title> <script language=" javascript "type=" text/ JavaScript "> var regexp=/\s\*/g; /*---------------String Object------------------* * var str= "This *is *test *string"; var stxt=str.charat (3); var atxt=str.charcodeat (3); var btxt=str.indexof ("s"); var ctxt=str.slice (0,4); var dtxt=str.split (""); var subtxt=str.substr (0,4); var regtxt=str.match (REGEXP); var regsearchtxt=str.search (REGEXP); Document.writeln ("Original string:" +str+ "<br>"); Document.writeln ("CharAt (3), return index character:" +stxt+ "<br>"); Document.writeln ("charCodeAt (3), return Unicode character code:" +atxt+ "<br>"); Document.writeln ("IndexOf, return the specified character index" +btxt+ "<br>"); Document.writeln ("Slice" (0,4), returns the characters between 0,4: "+ctxt+" <br>"); Document.writeln ("split") to intercept the word Fu Cheng array in a space: "+dtxt+" <br>); Document.writeln ("substr (0,4), intercepts characters between two indexes:" +subtxt+ "<br>"); Document.writeln ("Match, return matching string:" +regtxt+ "<br>"); Document.writeln ("Search, return the cheap location of the matching string:" +regsearchtxt+ "<br>"); /*-----------------Regular expression---------------/*//test var result_tst=regexp.test (str); Document.writeln ("Regexp.test (str), return match:" +result_tst+ "<br>"); EXEC var result_exec=regexp.exec (str); Document.writeln ("Return matching content:" +result_exec+ "<br>"); var result=str.replace (RegExp, "_"); Document.writeln ("Return the replaced content:" +result+ "<br>"); matching rule var reg2=/:\s*\w*\s*[0-9]+\s[0-9]{4}/; var reg1=/:\d*\s*\d+\s\d+/; var reg3=/w*@w+.w/; var str2= "This is a Date:march 12 2010"; var etxt=str2.match (REG2); Document.writeln (etxt+ "<br/>"); *----------------Date Object--------------------/var now=new date (); var hours=now.gethours () +7*24; Now.sethours (hours); document.write ("One weeks later:" +now+ "<br>"); Document.wriTe ("is Now" +now.getfullyear () + "year" + (Now.getmonth () +1) + "month" +now.getdate () + "Day" +now.gethours () + "+now.getminutes" () + "min" "+now.getseconds () +" seconds "+" <br> "); Timer function Counttime () {var targettime = new Date (2010,6,24,12,0,0,0); var nowtime = new Date (); Distance target time var distantime=targettime.gettime ()-nowtime.gettime (); Days = Math.floor (DISTANTIME/1000/60/60/24); Hours = Math.floor (DISTANTIME/1000/60/60-(* days)); minutes = Math.floor (distantime/1000/60-(24*60*days)-(60*hours)); Seconds =distantime/1000-(24*60*60*days)-(60*60*hours)-(60*minutes); Secondsround = Math.Round (seconds); document.getElementById ("Days"). Innerhtml= "<font color=red>" +days+ "</font>"; document.getElementById ("Time"). Innerhtml=hours+ ":" +minutes+ ":" +secondsround; } setinterval ("Counttime ()", 250); Array var firstarr=new array ("One", "two", "three"); var secondarr=["One", "two", "three"]; var remove=firstarr.slice (2,3); var splicarr=secondarr.splice (1,1); document.writeln (remove+ "<br>"); Document.writeln (splicarr+ "<br>"); Queue var fifoarr=new Array (); Fifoarr.push ("Apple"); Fifoarr.push ("banana"); var length=fifoarr.push ("Cherry"); Document.writeln ("The length of the array is:" +length+ "The contents of the array are:" +fifoarr+ "<br>"); Fifoarr.shift (); Document.writeln ("Remove the first element using the shift command:" +fifoarr+ "<br>"); Fifoarr.unshift ("Addfruite"); Document.writeln ("Add the first element using the Unshift command:" +fifoarr+ "<br>"); Fifoarr.pop (); Document.writeln ("Use Pop command last element:" +fifoarr+ "<br>"); </script> </pead> <body> <span> distance one day and </span><span id= "Days" ></span> Day < Span id= "Time" ></span> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.