Java Knowledge Summary-17

Source: Internet
Author: User
Tags readline

"JS Common knowledge"

Data type
String null Undefault numeric Boolean Array object

Array manipulation
var B = A.shift (); Deletes the first item of the original array and returns the value of the deleted element; returns undefined if the array is empty
var B = A.unshift ( -2,-1); Unshift: Adds a parameter to the beginning of the original array and returns the length of the array
var B = A.pop (); Pop: Deletes the last item of the original array and returns the value of the deleted element; returns undefined if the array is empty
var B = A.push (6,7); Push: Adds a parameter to the end of the original array and returns the length of the array
var B = A.concat (6,7); Concat: Returns a new array that consists of adding parameters to the original array
var B = A.reverse (); Array reverse order
var B = A.sort (); Sort by Set parameter array
var B = A.join ("|"); Sets the element group of the array as a string, separator as a delimiter, and the default comma delimiter if omitted
---splice (start,deletecount,val1,val2,...) : Deletes the DeleteCount entry starting from the start position and inserts the Val1,val2 from that position,...


Defined
var any type of variable
Function name (A, b) {} Defines a--a b for parameter name return value no need to define direct return
Function name () {property} defines an object--the object can be defined first and then added outside the object


Arguments[0] represents the first parameter of the method, in which no formal parameter is forced to pass in a parameter is a method of taking arguments

If JS adds a node event, ******.onclick=function () {test (this)}--Incoming parameter
. onclick=test-Note that this method is only known as a child


Import JS code (such as Import my97 control progress bar control JQuery, etc.)
Example: Import my97
<script language= "javascript" type= "Text/javascript" src= "My97datepicker/wdatepicker.js" ></script>

The prototype mode of JS Object
Student.prototype.a= "444"--Add an attribute a value of 444 for the prototype

Logical statements
for (var a = x in array) {}
for (Var x=0,x<5,x++) {}
if (test) {} else {}
while (test) {}
Switch (x) {Case 1: **break:case 2: **break:default:***}

Output debugging
Use the Window.alert () pop-up warning box.
Use the document.write () method to write content to the HTML document stream. The document is overwritten by using document.write () after the document is loaded
Writes to an HTML element using InnerHTML.
Use Console.log () to write to the browser's console.


Form validation *
var x=document.forms["MyForm" ["FName"].value; Get form [myForm] input box name [fname] Value---for JS verification

Regular validation:
var pattern = new RegExp ("S $");
Instantiate a regular validation of S $
--------
Attribute LastIndex (looking forward from the back) True/false
Source Property
Method Compile Method | exec Method | Test method
---------------
Exec runs a lookup in a string with a regular expression pattern, and returns an array containing the result of the lookup
Rgexp.exec (str)
******************************
Test returns a Boolean value that indicates whether a pattern exists in the string being looked up.
Rgexp.test (str)
*******************************
Stringobj.match (RGEXP)/////////
Match uses the regular expression pattern to perform a lookup on a string and returns the result that contains the lookup as an array.
The array returned by the match method has three properties: input, index, and LastIndex. The Input property contains the entire searched string. The Index property contains the position of the substring that matches the entire searched string. The LastIndex property contains the next position of the last character in the last match.

Manipulating page Element dom
Get:
var X=document.getelementbyid ("Intro"); Get elements by ID
var y=x.getelementsbytagname ("P"); The element is obtained by tag, as an array, containing all elements of that type as an example: elements of all paragraphs
var x=document.getelementsbyclassname ("Intro"); Get an array of elements by name
function Getelementsbyclassname (n)//Get Elements through class

Change content, properties, styles:
document.getElementById (ID). innerhtml=new HTML//Change the contents of an element
document.getElementById (ID). attribute=new value//Change the attributes of an element
document.getElementById (ID). style.property=new style//change element css (style)

********************
Dom (Document Object model) operation
=-09876549:37 2017/6/103-+tml All things in Dom are nodes, 1-Find nodes *
getElementById () Gets the node of the element by ID
getElementsByTagName () Get all the nodes through the tag
Childnode.parentnode getting the parent node of a known node

Manipulating HTML nodes
node. innerHtml--Add HTML tags to tag content
Add a node (example)--Find the parent node first
First create a tag in memory and add it to document
var para=document.createelement ("P"); Create a P tag
var att=document.createattribute ("*"); Create an attribute node
can also be directly setAttribute ()
var Node=document.createtextnode ("This is a new paragraph."); Create a text node
-----
Para.appendchild (node); Add text to the P element node
Para.appendchild (ATT); Adding attributes to the P element node
-----
var Element=document.getelementbyid ("Div1"); Find an Element
Element.appendchild (para); Add the created element to the node

Delete a node
var Parent=document.getelementbyid ("Div1"); Get a parent node
var Child=document.getelementbyid ("P1"); Get the child node under the parent node
Parent.removechild (child); To delete a child node from the parent node
*********
Child.parentNode.removeChild (child); Call the child element's method parentnode get the parent element, and then delete the

Copy a node
CloneNode (Boolean) Whether to copy child nodes

Event:
The onload and OnUnload events are triggered when the user enters or leaves the page onchange (content Change event) onmouseover and onmouseout (mouse hover off event) onmousedown, onmouseup, and Onclic K Event (mouse down press to lift click)

Get the browser model BOM parameters (all Windows can be omitted)
The Window.screen object contains information about the user's screen
The Window.history object contains the history of the browser.
The Window.location object is used to obtain the address (URL) of the current page and redirect the browser to a new page.
The Window.navigator object contains information about the visitor's browser.
**********************
Pop-up window:
Window.alert ("A"); A text--normal pop-up box
Window.confirm ("A"); A text-the pop-up box to be confirmed---can accept the return value of the Booleaan type
Window.prompt ("A", "B"); /a hint text B input box default text---can accept input pop-up box
Timer:
Window.setinterval (A, B)//a the number of milliseconds that are performed by the interval---interval, and the code is automatically executed
Window.clea/rinterval (A)//a global variables when creating timers--closing the Loop execution method
Window.settimeout (A, A, b) the number of milliseconds that the//a executes the interval of the specified number of milliseconds---pause specified
Window.cleartimeout (A)//a global variable when the timer is created--the method of closing timed execution

Common built-in objects for JS
Number
String
Date
Array
Boolean
Math
Window (default)--window
Document Text Block Object

String object:
var str=new String ();
Str.indexof ();//To return the position of the specified content in the original string, or 1 if not.
Str.trim ();//Remove whitespace before and after the string.
Str.concat ();//For stitching strings, it is the same as the effect of the plus sign, usually we use a plus sign to connect the string.
Str.substring (start,end);//start position, intercept to end, end cannot be taken.
Str.substr (start,length);//start position, intercept length string, if not write length value is truncated to the end by default.
Str.replace ();//Replaces an element of a string and returns the replaced string.
Str.split ();//Returns the string in the form of an array.
String also has the length property, which is used to return string lengths


Array Object
Arr.concat (Arrayx ...) Used to concatenate two or more arrays, where arrax can be an array, or it can be a specific value, with each item separated by commas.
Arr.join ();//used to return a string containing all the elements in the array, by default with a comma as the delimiter, but in parentheses can define the style of the delimiter, such as the vertical line is Arr.join ("|"); The delimiter is wrapped in semicolons.
Arr.push ();//Add one or more elements like the end of the array and return the length of the new array. The added elements are enclosed in parentheses and separated by commas. Note: The return value of this method is the length of the new array.
Arr.reverse ();//Reverses the order of the elements in the array. Directly calling this method only after the function has been reversed order, direct Console.log (arr) can directly output the sorted array.
Arr.sort ();//used to sort the array. If the method is called without parameters, the elements in the array are sorted alphabetically, with more precise points, sorted in the order of character encodings. If you want to sort by other criteria, you need to provide a comparison function to define the order of the sort.
Arr.tostring ();//Convert the array to a string and return the result, the returned string is separated by commas by default.

Date Object (Day object)
Date.getfullyear ();//Returns the year from the Date object (that is, the date here).
Date.getmonth ();//Returns the month from the date object. Note: The month here is to return 0 to 11 of the number, 0 corresponds to January, 1 corresponds to February, so remember to add one when using.
Date.getdate ();//Returns a day in one months from a Date object.
Date.getday ();//Returns a day in one weeks from a Date object. Note that the return is also a number starting from 0, 0 corresponds to Sunday, 1 corresponds to Monday, and 6 corresponds to Saturday.
Date.gethours ();//Returns the hour of the Date object (0~23).
Date.getminutes ();//Returns the minute of the Date object (0~59).
Date.getseconds ();//Returns the number of seconds (0~59) of the Date object.
Date.gettime ();//Returns the number of milliseconds from January 1, 1970 to the Date object.
Date.getlocatio?????? Returns the time format of the local format
Arr.valueof ();//Returns the original value of the array object, that is, returns the entire array.

Math Object
Math.Abs (x);//The absolute value used to return a number
Math.ceil (x);//Rounding up, For example 1.1,1.9 the two number returned is 2, if the number is passed in negative words, such as -1.1,-1.9, the return value is-1, at first it is easy to confuse, why not-2, at this time as long as the number of axes, you can clearly see, positive upward rounding is the direction of the net, then negative is the same.
Math.floor (x);//downward rounding, just opposite to Math.ceil () method.
Math.max (x, y,...); /return the maximum value in all the numbers in parentheses, note that the number in parentheses can be any number.
Math.min (x, y,...); /returns the minimum value in all the numbers in parentheses. As with Math.min (), the numbers in parentheses can be any number.
Math.pow (x, y);//returns the Y power of the computed x. Which is the value multiplied by y x.
Math.Round (x);//Returns the result of X rounding.
Math.random (x);//Returns a random number from 0 to 1, note that 0 here is available, but 1 is not.


Operation Flow
First, the function to achieve the core: FileSystemObject object in fact, to implement the file operation in JS, mainly by FileSystemObject objects.
Second, FileSystemObject programming trilogy
Editing with FileSystemObject takes the following steps: Create FileSystemObject objects, apply related methods, access related properties,
(a) Create the FileSystemObject object, and create the code for the FileSystemObject object as long as 1 lines:
var fso=new activexobject ("Scripting.FileSystemObject"); Instantiation of
When the above code is executed, the FSO becomes a FileSystemObject object instance.
(ii) Apply relevant methods, such as creating a text file:
var fso=new activexobject ("Scripting.FileSystemObject"); Instantiation of
var f1=fso.createtextfile ("E:\\b.txt", true); Create Notepad
(c) Access to the relevant properties, to access the relevant properties, the first to establish a handle to the object, which is achieved through the Get series method: Getdrive is responsible for obtaining the drive information, GetFile is responsible for obtaining the file information. For example, when you point to the following code, F2 becomes the handle to the file E:\\a.txt and gets the property.
var fso=new activexobject ("Scripting.FileSystemObject"); Instantiation of
var f1=fso.createtextfile ("E:\\b.txt", true); Create Notepad
var f2=fso. GetFile ("E:\\a.txt");
Alert ("File Last Modified:" +f2. DateLastModified); Show last Modified time
But one thing to note is that for objects created using the Create method, you no longer have to use the Get method to get an object handle, and the handle name created directly using Create can
var fso=new activexobject ("Scripting.FileSystemObject"); Instantiation of
var f1=fso.createtextfile ("E:\\b.txt", true); Create Notepad
Alert ("File Last Modified:" +f1. DateLastModified); Show last Modified time
Third, Operation Driver (Drives)
Using the FileSystemObject object to programmatically manipulate drives (Drives) and folders (Folders) is easy
A The Drives object properties drive object collects the contents of the physical or logical drives resource in the system, which has the following properties:
TotalSize: The drive size is calculated in bytes (byte).
FreeSpace: The free space for the drive is calculated in bytes (byte).
DriveLetter: Drive letter
Drive type: Removable (mobile media), fixed (stationary media), Netword (network Resource), CD-ROM, or RAM disk
SerialNumber: Serial Code of the drive

Example:
var fso=new activexobject ("Scripting.FileSystemObject"); Instantiation of
var drv=fso. Getdrive (FSO. GetDriveName ("c:\\")); Read Drive
var s= "";
s+= "Driver C:" + "-";
S+=drv. Volumename+ "\ n";
s+= "Total Space:" +drv. totalsize/1024;
s+= "KB" + "\ n";
S+=drv. freespace/1024;
s+= "Kb" + "\ n";
alert (s);

Iv. Operation folder
var fldr,s= "";
var fso=new activexobject ("Scripting.FileSystemObject"); Instantiation of
Fldr=fso. GetFolder ("c:\\");//Get Diver Object
Alert ("Parent folder name is" \ +fldr+ "\ n");//Display Parent directory name
Alert ("Contained on Drive" +fldr. Drive+ "\ n");//Display the drive name
if (Fldr. IsRootFolder)//Determine if the root directory
Alert ("This is the root folder.");
Else
Alert ("This folder isn ' t a root folder.");
Fso. CreateFolder ("C:\\bogus");//

Build a new file
Alert ("Create folder C:\\bogus" + "\ n");
Alert ("Basename=" +fso. Getbasename ("C:\\bogus") + "\ n");//Display the folder base name, not including the path name
Fso. DeleteFolder ("C:\\bogus");
Alert ("Deletedd folder C:\\bogus" + "\ n");//Delete folder

V. Operating documents

(i) Create a file
var fso=new activexobject ("Scripting.FileSystemObject"); Instantiation of
var f1=fso.createtextfile ("E:\\b.txt", true); Create Notepad
var forwriting=2;
var ts=fso. OpenTextFile ("E:\\c.txt", forwriting,true);//Another way to create a text file


(ii) Read and write data
var fso=new activexobject ("Scripting.FileSystemObject"); Instantiation of
var f1=fso.createtextfile ("E:\\b.txt", true); Create Notepad
F1. WriteLine ("testing"); Fill in a line of values with newline characters
F1. WriteBlankLines (3);//Fill in 3 blank lines
F1. Write ("This is a test");//fill in a line
F1. Close ();//Closed stream
var forreading=1;
F1=fso. OpenTextFile ("E:\\b.txt", ForReading);//Open File
S=f1. ReadLine ();//read a line to the string s
alert (s);

Vi. moving, copying and deleting files
var fso=new activexobject ("Scripting.FileSystemObject"); Instantiation of
F1=fso. GetFile ("F:\\b.txt");//Read source directory
F1. Copy ("D:\\b.txt");//Copy to Directory
F1. Move ("E:\\b.txt");//move to the directory, move the file
F1. Delete ();//Remove file


s operation file. txt. doc. xls
<script type= "Text/javascript" >
var fso = new ActiveXObject ("Scripting.FileSystemObject")
Fso. CreateFolder ("C:\\bonus");//Create a folder in the C drive
Fso. DeleteFolder ("C:\\bonus");//delete the created folder
Fso. CopyFile ("C:\\temp\\11.bmp", "c:\\bonus\\22.bmp");//Copy files
Create a new file
var tf = fso. CreateTextFile ("C:\\testfile.txt", true);
Tf. WriteLine ("Testing 1, 2, 3."); Fill in the data and add line breaks
Tf. WriteBlankLines (3); Add a blank line
Tf. Write ("This is a test."); Fill in one line with no line break
Tf. Close (); Close File
Open File
var forreading=1;
var ts = fso. OpenTextFile ("C:\\testfile.txt", ForReading);
s = ts. ReadLine (); Reads a row of files into a string
Alert ("File contents = '" + S + "'"); displaying string information
Rsh Close (); Close File
</script>


<script language= "JavaScript" >
var excelapp = new ActiveXObject ("Excel.Application"); Start the application that created the object Excel
var excelsheet = new ActiveXObject ("Excel.Sheet"); Create an Excel worksheet
ExcelSheet.Application.Visible = true; Make Excel window visible
Place some text in the first pane of the table.
ExcelSheet.ActiveSheet.Cells (a). Value = "This is column A, row 1";
Save Excel to C:\TEST. Xls.
Excelsheet.saveas ("C:\\test1. XLS ");
Use the Quit method to close Excel.
Excelapp.quit ();
can find C:\TEST1. XLS file, check its correctness
</script>
<script language= "JavaScript" >
Start Excel
var excelapp = new ActiveXObject ("Excel.Application");
Excelapp.visible = true; Make Excel window visible
ExcelApp.WorkBooks.Open ("C:\\test.xls");
var Objexcelbook=excelapp.activeworkbook;
var objexcelsheets=objexcelbook.worksheets;
var objexcelsheet=objexcelbook.sheets (1); Specifies that the current workspace is Sheet2
Here is the statement that fills in the data for the Excel cell
Objexcelsheet.range ("B2:k2"). Value=array ("Week1", "Week2", "Week3", "Week4", "Week5", "Week6", "Week7");
Objexcelsheet.range ("B3:k3"). Value=array ("67", "87", "5", "9", "7", "45", "45", "54", "54", "10");
Objexcelsheet.range ("B4:k4"). Value=array ("10", "10", "8", "27", "33", "37", "50", "54", "10", "10");
Objexcelsheet.range ("B5:k5"). Value=array ("23", "3", "86", "64", "60", "18", "5", "1", "36", "80");
Objexcelsheet.cells (3,1). Value= "InternetExplorer";
Objexcelsheet.cells (4,1). Value= "Netscape";
Objexcelsheet.cells (5,1). Value= "Other";
Objexcelsheet.saveas ("C:\\test2. XLS "); Save to C:\TEST2. Xls
Excelapp.quit (); Exit Excel
</script>


<script language= "JavaScript" >
WordApp = new ActiveXObject ("Word.Application"); Start Word
WordApp.Application.Visible = true; Make the Word window visible
var mydoc=wordapp.documents.add ("", 0, 1); Create a new document
wordapp.activewindow.activepane.view.type=3; Word view mode is page
WordApp.Selection.TypeText ("test Case"); Input string
WordApp.Selection.HomeKey (5,1); Cursor moves to the beginning of the line
WordApp.Selection.Font.Bold = 9999998; Wdtoggle
WordApp.Selection.WholeStory (); Select the entire document content
MyDoc. SaveAs ("C:\\test.doc"); Disk to C:\Test.doc
for (i=wordapp.documents.count;i>0;i--) {//Close all open Word documents
Wordapp.documents (i). Close (0);
}
WordApp.Application.quit (); Quit Word
</script>

Java Knowledge Summary-17

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.