Lesson Eleven
String Introduction of objects
1: attribute
     stay javascript You can use single quotation marks in , Or a character enclosed in double quotation marks as
     An instance of a character object , So you can add... After a string . To call String
     Properties and methods of objects .
    
     for example
    length return string Length of object , Represents the number of characters in a string .
    " Hello everyone ".length;// The length of the string is 3, Each man represents a character
    
2: Common methods
    indexOf(substring[,startIndex])
         Used to return the character position where the substring first appears , If no designation is found
         String , Then return to -1;
        substring: Required parameters , To be in string Object
        startIndex: Optional parameters , Start at the specified location
         The case is as follows

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Methods that call functions 1</title>
<script language="javascript">
var str="hello world";
var str_length=str.indexOf("o",3);
alert(str_length);
</script>
</head>
<body> </body>
</html>

substr(start[,length])
         A string used to return the specified string .
        start: Required parameters , Used to specify the starting subscript to get the substring . If one
             It's a negative number , So it means starting from the end of the string .-1 Represents the last character
            -2 Represents the penultimate character , And so on
        length: Optional parameters , Used to specify the number of characters in a string , If omitted
            , Return from start Substring from the beginning to the end of the string .
         The case is as follows

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Methods that call functions 1</title>
<script language="javascript">
var a="hello world";
var subs=a.substr(4,7);
alert(subs);
</script>
</head>
<body> </body>
</html>

    substring(from[,to])
        from: The first character used to specify the substring to get is in string Position in
        to: Optional parameters , Specify the last position
        [from,to) Before closed after opening , contain from, It doesn't contain to, So if you want to get to Of
             character , need to+1;
    The case is as follows

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Methods that call functions 1</title>
<script language="javascript">
var a="hello world";
var subs=a.substring(6,11);
alert(subs);
</script>
</head>
<body> </body>
</html>

    split(delimiter[,limit])
         Used to split a string into an array of strings
        delimiter: The specified separator
        limit: Optional parameters , Used to specify the maximum length of the returned array .
         Return value : An array of strings
         The case is as follows

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Methods that call functions 1</title>
<script language="javascript">
var a="hello.world";
var arr=a.split(".");
for(var i=0;i<arr.length;i++){
alert(arr[i]);
}
</script>
</head>
<body> </body>
</html>

  The twelfth lesson
Math And Date Introduction of objects
1:Math object
     In the use of Math Object cannot be used new Keyword create instance , Instead, use objects directly
     name . Members in this format
     The case is as follows
        alert(Math.PI);
        alert(Math.random());
        alert(Math.max(3,45,48578));
        alert(Math.min(-45,456,787);
2:Date object
  The case is as follows

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Methods that call functions 1</title>
<script language="javascript">
function sysTime(){
var now=new Date();// establish Date() object
var year=now.getFullYear();// Get year
var month=now.getMonth()+1;// Get month
var date=now.getDate();// Acquisition date
var day=now.getDay();// Get the day of the week
var hour=now.getHours();// For hours
var minutes=now.getMinutes();// Get minutes
var sec=now.getSeconds();// Get seconds
var day_week=Array(" Monday "," Tuesday "," Wednesday "," Thursday "," Friday "," Saturday "," Sunday ");
var week=day_week[day];
var time=year+" year "+month+" month "+date+" Japan "+week+hour+" when "+minutes+" branch "+sec+" second ";
document.getElementById("clock").innerHTML=" Current system time "+time;
} </script>
</head>
<body onload="sysTime()"> <div id="clock"></div>
</body>
</html>

The results of the case are as follows


The case of automatic system time change is as follows

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Methods that call functions 1</title>
<script language="javascript">
function sysTime(){
var now=new Date();// establish Date() object
var year=now.getFullYear();// Get year
var month=now.getMonth()+1;// Get month
var date=now.getDate();// Acquisition date
var day=now.getDay();// Get the day of the week
var hour=now.getHours();// For hours
var minutes=now.getMinutes();// Get minutes
var sec=now.getSeconds();// Get seconds
var day_week=Array(" Monday "," Tuesday "," Wednesday "," Thursday "," Friday "," Saturday "," Sunday ");
var week=day_week[day];
var time=year+" year "+month+" month "+date+" Japan "+week+hour+" when "+minutes+" branch "+sec+" second ";
document.getElementById("clock").innerHTML=" Current system time "+time;
} window.onload=function(){// Anonymous functions
window.setInterval("sysTime()",1000);// Loop call system time }
</script>
</head>
<body> <div id="clock"></div>
</body>
</html>

The case runs as follows


                        

The thirteenth lesson
window Introduction of objects
1:window object
    window Object is the browser window object , Is the top-level object of all objects ,window object
     Provides many properties and methods , These properties and methods are used to manipulate the content of the browser page

window Objects and Math object , You don't need to use new Keyword create object instance
Instead, use the object name directly . Member to access its properties or methods

2:window Common properties of objects
    document            For windows or frames that contain documents document Read only reference to object
    defaultStatus      A readable character , Used to specify the default message in the status bar
    frames                Represents all the objects in the current window frame A collection of objects
    location              Used to represent a window or frame location object , If you take a URL Assign to the attribute , Then the browser will load and display the URL The specified document
    length                The number of frames in a window or frame
    history               For windows or frames history Object read-only reference
    name                 The name used to store the window
    status                A character that can be read and written , Used to specify the current information in the status bar
    top                   Represents the top browser window
    parent              Represents the parent window that contains the current window
    opener             Represents the parent window that opens the current window
    closed              A read-only Boolean value , Indicates whether the current window is closed
    self                  Represents the current window
    screen             For windows or frames screen Read only reference to object , Provide screen size , Color depth and other information
    navigator         For windows or frames navigator Object read-only reference , adopt navigator Object to get browser related information     

The simple case is as follows ( Output content document.write() Four formats of )   

document.write()  Can be used directly to HTML Output stream writes content . Simply put, it is to output content directly in the web page .

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> First time to know window object </title> <script language="javascript">
document.write("hello");
var str="world";
document.write(str); var str2="biexiansheng";
document.write(str2+" He's a handsome guy "); var str3="hello";
document.write(str3+"<br/>");
</script>
</head>
<body> </body>
</html>

Warning (alert Message dialog )

When we visit the website , Sometimes a small window pops up , There's a message on it . If you don't click “ determine ”, You can't do anything with the web , This small window is to use alert Realized .

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> First time to know window object </title> <script language="javascript">
alert("hello");
alert("world");
</script>
</head>
<body> </body>
</html>

confirm (confirm Message dialog )

confirm Message dialog boxes are often used to allow the user to make selected actions , Such as :“ Are you right ?” etc. . Pop-up dialog box ( It includes a OK button and a cancel button ).

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> First time to know window object </title> <script language="javascript">
var message=confirm(" You like it javascript Do you ???");
if(message==true){
document.write(" If you like it, study hard ");
}else{
document.write(" If you don't like it, you should study hard ");
}
</script>
</head>
<body> </body>
</html>

put questions to (prompt Message dialog )

prompt Pop up message dialog box , It's usually used to ask for information that needs to interact with users . Pop up message dialog box ( Contains an OK button 、 Cancel button with a text input box ).

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> First time to know window object </title> <script language="javascript">
var myname=prompt(" Hello , Please enter a name ");
if(myname!=null){
alert(" Hello "+myname);
}else{
alert(" Hello my friend.");
}
</script>
</head>
<body> </body>
</html>

3:window Common methods of objects
        alert()                                  A warning dialog box pops up
        confirm()                             Display a confirmation dialog , When you press the confirm button, return to true, Otherwise return to false
        prompt()                             A prompt dialog box will pop up , And asked to enter a simple string
        blur()                                   Remove the focus of the keyboard from the top browser window
        close()                                close window
        focus()                               Focus the keyboard on the top browser window
        open()                               Open a new window
        scrollTo(x,y)                      Scroll the window to (x,y) The position specified by the coordinates
        scrollBy(offsetx,offsety)    Scroll the window by the specified amount of displacement
        setTimeout(time)               Execute the code after a specified time
        clearTimeout()                  Cancels delayed execution of the specified code
        moveTo(x,y)                      Move the window to an absolute position
        moveBy(offsetx,offsety)   Move the window to the specified displacement
        resizeTo(x,y)                    Set the size of the window
        print()                              It's equivalent to the print button on the browser toolbar
        setInterval()                     Cycle executes the specified code
        clearInterval()                  Cancel periodic code execution

  Examples are as follows :

Open a new window (window.open)

open() Method to find an existing or new browser window .

grammar :

window.open([URL], [ Window name ], [ Parameter string ])
Window name _blank: Show target page in new window   _self: Display the target page in the current window   _top: Frame page displays the target page in the upper window
Parameter string : Optional parameters , Set window parameters , The parameters are separated by commas .

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> First time to know window object </title> <script language="javascript">
function check(){
window.open("http://www.bjlemon.com/","_blank",width=600,height=500,top=20,left=60);
}
</script>
</head>
<body> <form>
<input type="button" value=" Click on " onclick="check()">
</form>
</body>
</html>

close window (window.close)

close() close window


 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> First time to know window object </title> <script language="javascript">
function check(){
var no=window.open("http://www.bjlemon.com/","_blank",width=600,height=500,top=20,left=60);
no.close();
}
/*var no=window.open("http://www.bjlemon.com");
no.close();*/
</script>
</head>
<body> <form>
<input type="button" value=" Click on " onclick="check()">
</form>
</body>
</html>

  The comprehensive exercise code is as follows

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> First time to know DOM</title> <script language="javascript">
function openWindow(){ var con=confirm(" The confirmation dialog box will pop up , Please confirm or cancel ");// Confirmation dialog , Double quotes
if(con==true){
var myurl="http://www.imooc.com";
var pro=prompt(" Please enter the web address ",myurl);// If it's defined url, Then you can't quote
window.open(myurl,'_blank');// If it's defined url, Then you can't quote
}else{
alert(" Please reconfirm your operation ");
}
}
openWindow();
</script>
</head>
<body> </body>
</html>

The results of comprehensive exercise are as follows


         

                               

Javascript in String Simple learning of the object of more related articles

  1. JavaScript in String Object's match()、replace() Use with regular expressions

    Regular expressions have a long history , Finding and replacing is very powerful , But templates are hard to remember and complicated . JavaScript in String Object's match().replace() this 2 All methods use the template of regular expression . When the template content does not match the string , ...

  2. JavaScript in String Object method introduction

    1. Character method 1.1 charAt() Method , Returns the character at the specified position in the string . var question = "Do you like JavaScript?"; alert(ques ...

  3. Javascript in DOM Simple learning of Technology

    lesson fourteen DOM Technology overview 1:DOM summary Document object model DOM(Document Object Model) Define access and processing HTML Standard approach to documentation .DOM  take HTML The document is rendered with elements . Attribute and text tree structure ( section ...

  4. javascript in string Object method slice、substring、substr The difference between

    1.slice.substring.snustr All belong to String The object method of , Used to intercept or extract string fragments , All three destroy the original string , Instead, it returns the extracted part with a new string . <script> va ...

  5. javascript in String object slice and substring difference

      1.slice(start,stop) and substring(start,stop)   Methods are used to extract strings from start Start to stop-1 The characters between ( Because the string index is from 0 Start ). among start have to ...

  6. JavaScript in String Object processing HTML How to mark Chinese text

    big(): Create a <big></big> Mark , Make the font of this string larger blink(): Create a <blink></blink> Mark , Make the string blink b ...

  7. javascript Objects in the , Prototype , Prototype chains and object orientation

    One .javascript Properties in . Method 1. First , About javascript The function in /“ Method ”, Here are two points : 1) If the object property being accessed is a function , It's easy for some developers to think that this function belongs to this object , So the “ Attribute access ” be called ...

  8. Javascript Objects and prototypes in ( One )( Reprint )

    Object oriented language ( Such as Java) There is the concept of class in , Through classes, you can create any number of objects with the same properties and methods . however ,JavaScript There is no concept of a class , So its objects are also different from those in class based languages . To understand object orientation , The first ...

  9. stay JavaScript The function and simple usage of closure in

    stay JavaScript The function and simple usage of closure in One . A brief introduction to closures Scope chain : stay js Only functions have the concept of scope in , Because the data outside the function can be accessed inside the function , The data inside the function cannot be accessed outside the function , From the above, a chain of scope access is formed ...

Random recommendation

  1. Be Better: Meet a better self -2016 Chronicle of the year

    In fact, there are no good words to describe the past year , I feel so flat ! Without the childishness of graduation , It seems that things are going down , A little less impetuous , More serious .2016 Maybe it's that sentence - Read more , More than a newspaper , Eat less snacks and sleep more , And I'd rather say --Be B ...

  2. struts2 + jquery + json Simple front and back information interaction

    ajax It is an interactive technology of asynchronous request between client and server . Compared to synchronous request , Greatly improve the speed and efficiency of information interaction . It's a very practical and popular technology right now . Here's a simple explanation struts2 + jquery + json Under the Letter ...

  3. Read high performance JavaScript Programming learning English Chapter one, page three, paragraph one

    When the browser encounters a <script> tag, as in this HTML page, there is no way of knowing w ...

  4. soupUI Generate webservice Client code

    stay Apache Web site to download axis2 software package , At the same time, this machine is installed with soapUI Tools . for example , Now I'm using axis2 Version is axis2-1.4-bin.zip,soapUI Version is 3.6. Apache Axis Download address : ...

  5. CAS Single sign on configuration [5]: Test and summary

    It's finally coming to an end ... test 1 We turn it on at the same time Tomcat6 and Tomcat7, If you report an error, please revise . hit Open the browser , Input http://fighting.com/Client1, Get into CAS Login screen , Here, let's enter ...

  6. The shortest path problem of graphs ———— Cows in trees (tree.cpp)

    As usual , Continue to introduce from the topic Cows in trees (tree.cpp) [ Title Description ] Farmer John My cows don't live on the ground, they live in trees QWQ. Cows need to visit each other , But before they visit, they will ask John Ask about the distance . But Jo ...

  7. oracle Database compatibility mysql Different ways of writing

    1.sysdate Change it to sysdate(), perhaps now(); 2.nvl(expr1,expr2) Change it to IFNULL(expr1,expr2) nvl2(expr1,expr2,expr3) Change it to IF( ...

  8. Logical operators 、 Ternary operator 、for loop 、stack( Stack ),heap( Pile up ), Method area , Static domain

    Lesson One 2018-04-17 19:58:39 Logical operators ( For logical operations , On both sides true or false) Logic and -& and Short circuit and -&& difference : & ...

  9. [Python] Getting started with multithreading

    original text :http://blog.csdn.net/ice110956/article/details/28421807 Python There are two ways to implement multithreading of : function , Thread class 1. function call thread modular ...

  10. docker machine Introduction and use

    https://www.cnblogs.com/sparkdev/p/7044950.html https://www.jianshu.com/p/cc3bb8797d3b