Javascript colon instructions

Source: Internet
Author: User

I am always confused, so I searched on the Internet and checked the information. I am very depressed that there are not many posts about the usage of colons on the Internet, and they are not deep enough, after two days, I finally got a better understanding of the colon (:). I hope it will be helpful to anyone who wants to know the usage of the colon.
1. switch statement Branch
2 ,? : False of a ternary expression
3. Declare members with direct object quantity
4. Declare tags

I believe everyone on Earth knows this, right? If someone doesn't know, all programmers on the earth will know, haha.
3. We often use the direct object volume. What is the direct object volume?
The object direct volume (also called the object initialization program) is composed of a list. The elements in this list are attribute/value pairs separated by colons. elements are separated by commas, the entire List is included in curly brackets.
Objects in javascript can have attributes and methods like objects in object-oriented languages C # and JAVA.
There are many ways to create javascript objects. For example, you can create javascript objects using objects,
Copy codeThe Code is as follows:
Var obj1 = new Object ();
Obj1.X = "20px ";
Obj1.Y = "30px ";
Obj1.myFunction = function () {alert ("I Am a method! ");};
Obj1.myFunction ();

Directly create an object using an object:
Copy codeThe Code is as follows:
Var obj2 = {X: "20px", Y: "30px", myFunction: function () {alert ("I Am a method! ");}}
Obj2.myFunction ();

Creating objects using objects directly seems simple.
Of course, you can first write something similar to the Class and then create it using the constructor:
Copy codeThe Code is as follows:
Function myClass (x, y ){
This. X = x;
This. Y = y;
}
MyClass. prototype. myFunction = function (){
Alert ("I Am a method! ");
}
Var obj3 = new myClass ("20px", "30px ");
Obj3.myFunction ();

4. Declare tags
There are many scripting languages. Apart from javascript, we can also use other scripting languages to implement the functions that javascript can implement;
Example:
<Input type = "button" onclick = "vbscript: vbFunction ()" value = 'button'/>
When you click the button, the vbscript syntax is used to execute the vbFunction method defined by vbscript;
If you change vbscript: vbFunction () after onclick to javascript: vbFunction ();, an error occurs.
You can call these statements without writing them,
<Input type = "button" onclick = "vbFunction ()" value = 'button'/>
In this case, whether you use vbscript or javascript in onclick, ie will identify and execute it with the corresponding syntax. Of course, other browsers do not support vbscript.
We usually use javascript to add declarations, that is, "javascript :",
<Input type = "button" onclick = "javascript: alert ('you clicked me! ') "Value =' button '/>
"Javascript:" It is often used by self-proclaimed hackers to bypass some simple or more advanced html form restrictions, cookie/session verification, and SQL injection. if you want to know about it, you can check it elsewhere, but you must never destroy it. Haha
A simple example:
Open www.baidu.com Baidu's homepage, copy the following sentence to the address bar of the browser, and press Enter,
Javascript: alert (document. forms [0]. wd. value = 'csdn '); document. forms [0]. submit ()
What is the effect? Yes, we use javascript to directly manipulate the text in the search box, and execute the form submission. For more complex operations, you can study it on your own.

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.