Php basic learning notes javascript (5)

Source: Internet
Author: User
: This article mainly introduces php basic learning notes javascript (5). For more information about PHP tutorials, see. Special characters in the string:

In js, the content of double quotation marks in double quotation marks and the content of single quotation marks in single quotation marks must be transferred in the following format:

Var str1 = "my mother say: \" don't speak with stranger \".";

Var str2 = 'My mother say: "don \'t speak with stranger ".';

Common escape characters in js include:

"? \"'? \ 'Carriage return? \ R line break? \ Ntab? \ T \? \ Note: The carriage return, line break, space, and tab are also equal to the, B, c, d, and ',', $ & and other symbols.

Date object:

Objects used to represent time and date data. A time and date object contains specific information about time and date, such as year, month, day, hour, minute, second, millisecond, and week.

Defining a time and date object can take the following forms:

D1 = new Date (); // defines a Date object indicating "Current Time", d2 = new Date ("11:18:19 "); use a string to define a Date object d3 = new Date (2013, 9, 25, 11, 18, 19) for a specified time (time); use multiple (at least 3) number to define a Date object of the specified time d4 = new Date (2324624252312); a number to define a Date object of the specified time.

This number indicates the number of milliseconds that have elapsed since midnight, January 1, January 1, 1970 (or even 0mm. Note: one second equals 1000 milliseconds. -- In fact, we can understand that in JavaScript, data such as "time" actually only stores a number. If this value is a negative value, it indicates the previous calculation. In fact, the time can be calculated by addition or subtraction.

This time point is generally regarded as the "time start point/origin point" of the computer world ".

Common methods of time objects:

V1 = d1.toLocaleString (); obtain the "local representation" v1 = d1.getTime (); obtain the "millimeters" of a time-starting from the time origin. The following is a data value in the retrieved Time: v1 = d1.getFullYear (); // The number of years obtained. it is a number, and v1 = d1.getMonth () is the same as the number of months. note: this number starts from 0, that is, it can only be: 0-11 v1 = d1.getDate (); // Obtain the number of days v1 = d1.getDay (); // Obtain the number of weeks v1 = d1.getHours (); // Obtain the number of hours v1 = d1.getMinutes (); // Obtain the number of minutes v1 = d1.getSeconds (); // Obtain the number of seconds v1 = d1.getMilliseconds (); // Obtain the number of milliseconds

The following is a data value in the set time:

D1.setFullYear (n); // set the annual number of copies of the d1 object to n, that is, the year of the object is modified, the same below. D1.setMonth (n); // set the number of months d1. setDate (n); // set the number of days d1. setDay (n); // set the number of weeks d1. setHours (n ); // set the number of hours d1. setMinutes (n); // set the number of minutes d1. setSeconds (n); // set the number of seconds d1. setMilliseconds (n); // set the number of milliseconds

Webpage object introduction

The first important concept is that every tag in an html file is an object.

Var obj1 = {name: "Xiaohua", age: 18, zuofan: functoin (){......}, Xiyi: function (){......}} Var v1 = obj1.age; alert (v1); obj1.age = 19; // A year later, adding one year old -- modified the value of the age attribute of the object obj1. Obj1.name = "Dahua ";

How to obtain the webpage tag object:

Var obj1 = document. getElementById ("id name ");

Tag attributes of the operation object:

Get: var v1 = obj1. tag attribute name;

Value assignment: obj1. tag attribute name = a value;

Style attributes of the operation object:

Get: var v1 = obj1.style. style attribute name; -- in fact, this method can only get its "intra-row style"

Value assignment: obj1.style. style attribute name = a value;

How to obtain the webpage tag object:

Var obj1 = document. getElementById ("id name ");

Tag attributes of the operation object:

Get: var v1 = obj1. tag attribute name;

Value assignment: obj1. tag attribute name = a value;

Style attributes of the operation object:

Get: var v1 = obj1.style. style attribute name; -- in fact, this method can only get its "intra-row style"

Value assignment: obj1.style. style attribute name = a value;

Preliminary Event

Simply put, an event is an action, that is, an operation of the user, such as clicking, moving the mouse, double-clicking ,......

First, review and strengthen the "definition" of js: js is an object-based event-driven scripting language.

Events:

Mouse event: onclick: onmouseover: onmouseout: ondblclick: Double-click event onmousedown: when the mouse is down (note that the mouse is not up yet) onmouseup: onmousemove occurs when the mouse is up: when the mouse moves-the movement is everywhere.

Keyboard event: onkeypress: one click. Onkeydown: onkeyup occurs when the key is pressed down. It occurs when the key is lifted.

Form event: onsubmit: onfocus occurs when a form is about to be "submitted": It occurs when a form item "obtains focus. Onblur: onchange occurs when a form item is "out of focus": when the data of a form item is changed-it is usually used only for the select label option change.

Others: onload: When a webpage is loaded successfully, that is, when the webpage is opened-onload can only appear once on a page. Onload can only be written on the body tag, or it is not written in the tag, but the real line of window. onload can be used in the script.

Summary: events occur at any time and are everywhere. they are only the objects on which we want to use the events to accomplish what work.

The basic code mode is:

    
 <标签名 …… on事件名="”函数名f1();”">
  
......
 Script function f1 () {// Here is what we want to do !!!!!} Script

The basic meaning is: when an event occurs for an object, a function is called to complete a task.

Event object

An event is an object inside a browser (note, not a webpage tag object). it represents a collection of event-related information when an event occurs (an object is a collection of information) -- it only exists when an event occurs!

Generally, an event is only used to obtain relevant information when an event occurs. for example, the coordinates (x and y) of the mouse at the moment are used to determine which webpage object has the event, which mouse button is triggered when an event occurs, or which keyboard key is used. The above information is obtained by the following event attributes:

Event. clientX -- obtains the x coordinate position of the mouse when an event occurs.

Event. clientY -- obtains the y coordinate position of the mouse when an event occurs.

Event.tar get -- get the tag object when the event occurs (applicable to FF) -- similar to the object obtained by getElementById

Event. srcElement -- get the tag object when the event occurs (applies to IE) -- similar to the object obtained by getElementById

-- The tag object when an event occurs is usually called the "event source ".

Event. keyCode -- key value of the key when a keyboard event occurs -- each key on the keyboard corresponds to a numeric value.

Comparison between this and event:
 <标签名1 on事件名="”函数名f1(this)”">
  
.....
     
 <标签名2 on事件名="”函数名f2(event)”">
  
.....
 Script function f1 (obj) {// in this range, obj represents the object "tag name 1", similar to the object obtained using getElementById} function f2 (evt) {// in this range, evt represents the event object when an event occurs. // Here, evt is used. Basically, the following attributes are used (as needed): var v1 = evt. clientX; // Obtain the x coordinate var v2 = evt at the time of the mouse. clientY; // Obtain the y coordinate var v3 = evt at the time of the mouse. keyCode; // Obtain the key value of the keyboard (only valid for keyboard events) var v4 = evt.tar get; // Obtain the event source object, IE is: evt. srcElement;} script

The above introduces the basic learning notes for php javascript (5), including some content, hope to be helpful to friends who are interested in PHP tutorials.

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.