JavaScript in the application process will encounter a variety of comparisons, today to all of you to organize three kinds of situation, together to learn.
1. Comparison of two objects
JavaScript comparisons are mixed with some of the more bizarre
The code looks like this:
var arr = [5,32,28,66,2,15,3];
Arr.sort (function (A1,A2) {return
a1-a2;//a2-a1 input Reverse
});
Console.log (arr);
Console.log (Arr.reverse ()); Reverse reverse the order of elements in an array
var arr2
constants: JavaScript constants, also called Literal constants, are the information that is solidified in program code.
variables: The main function of a variable is to access data, providing a container for accessing information.
var x = "XX";
y = "xxx";
Such. There's a problem here, for example, in a line in the code, I would like to use a declared variable x, the result of typing or spelling errors, the variable is written y, the result is equivalent to "implicit" declared
This article focuses on the first reason. Finally, a development pattern is given to replace the traditional loop structure, which can completely avoid the situation that the script is out of control.
Original title:Speed up Your JavaScript, part 1
This effect itself is not very difficult, mainly in the program structure and expansion of some kung Fu, in order to use more convenient, can be used in more places.
Program features
1, the same hint box used in multiple trigger elements, only one
1, reference
A reference is a pointer to the actual position of the object. Look at the following examples of using references:
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Copy Code code as follows:
function Get_cookie (name) {
var start = Document.cookie.indexOf (name+...= ...);
var len = start+name.length+1;
if ((!start) && (name!= document.cookie.substring (0,name.length)) return null;
if (start = =
1. Writing JS functions
2. HTML element to show/hide plus id attribute
control the show/hide of this TR
3, add buttons, links, etc trigger JS function
Show/Hide
JavaScript shows hidden layers Advertising
Two: JavaScript controls
1. Save HTML page to Word
Copy Code code as follows:
Cell 1
Cell 2
Cell 3
Cell 4
Cell merge
test
2. Generate Word with JS
Copy Code code as follows:
****
Originally want to use array to save data, did not try to use JS to data structure, use JS to try it.
JS efficiency is really very low a list of 1000 objects browser prompts you to run slowly.
Before think Ajax3d quite use the foreground, now it
namespace is called "namespaces", also known as "namespace", "namespace". JavaScript is not like C # or Java, there are special namespace and package syntax support, when JS complexity to a certain extent, especially the reference to a large number
Ways to add a function
function addevent (node, type, listener) {
if (Node.addeventlistener) {
The method of the Consortium (DOM method)
The false meaning in the following statement is for the bubbling phase, and if true is for the capture phase (ie
(1) Declare an expression variable and define the expression for that variable. Such as:
Copy Code code as follows:
var func = function ()
{
/*body code*/
}
(2) defines a function expression and specifies the identity
The concept of the event
Event: Refers to some specific interaction moments that occur in a document or in a browser window. We can use listeners (or handlers) to schedule events so that the corresponding code is executed when the event occurs.
I.
JavaScript does not need to be compiled to run, which allows JavaScript-built applications to become flexible. We can dynamically load JavaScript scripts from the server as needed to create and control the UI to interact with the user. The following
javascript timestamp and date string convert code to each other (super simple)
The above is a small series for everyone to bring the JavaScript timestamp and date string conversion code (super Simple) all the content, I hope that we
First look at the window effect, as follows:
Enlarge the picture $ (page). On (' click ', '. Popupimage img ', function () {var-= $ (this);
That.popupimage ({this:that, Width: "200px"})});
Album Pinball Window $.fn.popupimage = function (
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