JavaScript colon usage Description _javascript tips

Source: Internet
Author: User
Tags html form list of attributes sql injection
Old in front of the eyes, so on the Internet search it, check the information, very depressed online introduction of the colon usage of the post is not much, and relatively fragmented, and not deep enough to read people more confused, toss for two days, finally to the colon (:) has a further understanding, I hope to understand the use of colon to help people.
1, switch Statement Branch
2,?: three-dimensional expression of false
3. The member who declares the direct amount of the object
4, the Declaration label

1 and 2 believe the Earth knows, don't they? If someone does not know, then I change to become the Earth programmer all know, haha
3, the object direct quantity we also often use, what is the object direct quantity?
The object's direct volume (also known as an object initializer) consists of a list of attributes/value pairs separated by colons, separated by commas, and the entire list contained in curly braces.
Objects in JavaScript can have properties and methods like objects in C #, Java, and object-oriented languages.
There are a number of ways to create JavaScript objects, for example, you can create with object,
Copy Code code as follows:

var obj1 = new Object ();
Obj1. X = "20px";
Obj1. Y = "30px";
Obj1.myfunction = function () {alert ("I am a Method!") "); };
Obj1.myfunction ();

create an object with a direct amount of object:
Copy Code code as follows:

var obj2={x: "20px", Y: "30px", Myfunction:function () {alert ("I am a Method!") ");}}
Obj2.myfunction ();

creating objects with direct amounts of objects looks neat.
You can, of course, write a class-like thing first and then create it with a constructor:
Copy Code code as follows:

function MyClass (x, y) {
This. x = x;
This. y = y;
}
Myclass.prototype.myfunction=function () {
Alert ("I'm a Method!") ");
}
var obj3 = new MyClass ("20px", "30px");
Obj3.myfunction ();

4, the Declaration label
There are many scripting languages, in addition to JavaScript, we can use other scripting language to achieve the functions that JavaScript can achieve;
Cases:
<input type= "button" onclick= "Vbscript:vbfunction ()" value= "button"/>
When you click the button, you use VBScript syntax to perform the Vbfunction method you defined in VBScript.
If you change the vbscript:vbfunction () behind the onclick to Javascript:vbfunction (), you will get an error.
These statements you can also not write direct call method,
<input type= "button" onclick= "Vbfunction ()" value= "button"/>
At this point in the OnClick method, whether you use VBScript or Javascript,ie browser will be identified, with the corresponding syntax to execute, of course, other browsers do not support VBScript.
We usually use JavaScript as a statement, which is "javascript:",
<input type= "button" onclick= "Javascript:alert (' You clicked on me! ') ' value= ' button '/>
"javascript:" is often exploited by people who call themselves hackers, using "javascript:" to bypass some simple or more advanced HTML form limits and cookie/session validation; and SQL injection. If you want to know can go to other places to check, but learn not to sabotage ah, haha
Make a simple little example:
First Open www.baidu.com Baidu's homepage, and then directly copy the following sentence into the browser's address bar, press ENTER,
Javascript:alert (document.forms[0].wd.value= ' csdn ');d ocument.forms[0].submit ()
What's the effect? Yes, we use JavaScript to directly manipulate the text in the search box, as well as execute the form submission, more complex operations, you can study.
Related Article

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.