CopyCodeThe Code is as follows: (function (clover ){
Clover. loadscript = function loadscript (URL, callback ){
VaR heads = Document. getelementsbytagname ('head ');
If (heads. Length = 0 ){
Alert ("Page must have one head element ");
}
VaR
-- This starts with the javascript interpreter: every time the javascript interpreter starts to execute a function, it creates an execution environment, in addition, a variable object that is closely related to this function will be generated, and
At that time, Netscape's JavaScript caught the lead in the battle with IE's browser, and then ie created JScript to cope with Netscape's JavaScript. In fact, JScript basically copied JavaScript, this is one thing Microsoft has always been criticized
JS has nine data types: undefined, null, Boolean, string, and number), object, reference, and completion ). The last three data types only serve as the intermediate result of JS running. Therefore
Code For use in, the following describes the string:
The essence of this language function depends on the prototype chain pattern unique to JavaScript.
So strictly speaking, JavaScript is a prototype-based object-oriented language. That is to say, each instance object has a prototype. The object
Add a CSS class to a specified element:
By adding CSS classes to change the appearance and feeling of elements, it is a very clean method, rather than adding inline styles. With jQuery, it is easy:
$('#myelement').addClass('myclass');
Remove a CSS
1. js object-oriented implementation
Copy codeThe Code is as follows:
Ii. 6 simple data types:1) Undefined. A variable is defined but not assigned a value to it.2) Null. (reference type)3) Number. numeric typeVar num = 1.0 at this time, num is of
Composition
This is a very common Weibo list page, similar to Sina Weibo. Last weekend, a total of five objects were used to generate 400 lines of code, and a code organization mode was developed.
The code for easy task completion consists of four
Copy codeThe Code is as follows: Question: Write a function to remove the repeated values in the given array.
For example:
Input array a = [0, 8, 5, 4, 78, 8, 90, 4, 'A', 'B', 'a'];
Returned results: [, a, B]
I think about this question many times
Copy codeThe Code is as follows: function isNum () // judge the number entered by the keypad
{
Var str = (window. event. keyCode );
If (str> 105 | str {
If (str! = 8)
{
Window. event. returnValue = false;
Return;
}
}
}
Function isNumUp ()
Copy codeThe Code is as follows: $ (function (){
PageJs. urls = [
'/', 'Index ',
];
PageJs. run ();
});
// The functions include html elements. Ajax function also can be put here.
Var Common = {
Init: function (){
Alert ('common ');
}
};
// Url --
Copy codeThe Code is as follows:
test
The result is not similar to the general statement. Using array will be faster. In ie9, 8. Ff, google, sogou, and Other ie core browsers are tested. It is true that the array method is slower than the
Type assignment is similar to variable transfer.
You do not need to specify the basic data type.
Copy codeCode: var a = 5;
Var B =;
B = 3;
Alert (a); // prompt 5
Alert (B); // prompt 3
From this perspective, it is found that changing B will not
However, there are no classes. Why should we talk about object-oriented? It does not matter. It can be simulated. In addition, this method has become a recognized method for implementing object-oriented JavaScript.
In addition, if everything in JS
For the inheritance of classes in javascript, refer to Ruan Yifeng's Blog "design idea of Javascript Inheritance Mechanism.
I. Problems Encountered in javascript instantiation:
The following describes how to use the example in javascript advanced
Copy codeThe Code is as follows: // convert string to xml object
Function String2XML (xmlString ){
// For IE
If (window. ActiveXObject ){
Var xmlobject = new ActiveXObject ("Microsoft. XMLDOM ");
Xmlobject. async = "false ";
Xmlobject. loadXML
The XMLHttpRequest object is divided into four parts:
1. Create an XMLHttpRequest component
2. Set the callback function
3. initialize XMLHttpRequest Construction
4. Send a request
Instance code:
Copy codeThe Code is as follows: var userName;
Var
OldObj is an object, not a value
For example, var newObj = oldObj;
If you want to change the oldObj, newObj is not affected;
You can write a function like this.
Copy codeThe Code is as follows: function clone (myObj ){
If (typeof (myObj )! = 'Object'
The role of this mode is to ensure the real privatization of Object Attributes. We cannot directly access the object status and can only operate through privileged methods.
Here is an example.
Copy codeThe Code is as follows: var person = 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