1.javascript (Basic)

Source: Internet
Author: User

JS Basic section


JS Definition:

1.js is a scripting language that is parsed by the browser and then executed by the browser
2.CSS control style, and JS control behavior

Basic format:

<script type= "Text/javascript" >

Basic definition:

All types are defined with Var.


External style sheet (CSS):

<link rel= "stylesheet" href= "Stylesheet1.css" type= "Text/css"/>

External style sheet (JavaScript):
<script type= "Text/javascript" src= "Javascript1.js" ></script>


2. Basic mode of behavior:


1. Browser pop-up window alert ()//Browser popup () the contents of the popup window//Note: If JavaScript and CSS are executed together
Then JavaScript executes first, because it is the behavior

2.confirm ("Cue box")//Note: JS is a weakly typed language and C # is a strongly typed language

3.prompt: Collect text characters
parsefloat: Convert to Decimal

4.js Opening a new window

window.open ("Address", "title name");

5. Initial onboarding

Window.onload = KK;
function kk () {alert ("page Loaded Complete")}


6.document.getelementbyid (get ID);


3. Process Control


var ak12 = prompt ("Please enter your score")
ak12 = parsefloat (ak12);
if (Ak12 > 12)
{

Alert ("qualified");

}


4. Array definitions

Format of the array: var arr[];
var arr=new arrer ();


var arr = [12, 1, 122, 13];
var r = Add (arr);
Alert (R);
var sum = 0;
function Add (arr) {


for (var i = 0; i < arr.length; i++)
{

sum = sum + arr[i];


}
return sum;

}


5. Events

<script type= "Text/javascript" >

function Fun ()
{

Alert ("You have been clicked")

}


</script>
<body>
<input type= "button" value= "Test" onclick= "Fun ()"/>
</body>

Event 2:


Function Show ()
{

var input = document.getElementById ("text");
Input.value= "Welcome You"

}

</script>
<body>
<input type= "text" id= "text"/>
<input type= "button" value= "Test" onclick= "show ()"/>


Event 3: Get focus cleared window.onload = function ()
{

var input = document.getElementById ("text");
Input.onfocus = function ()
{

This.value = "";


}


}

Event 4: Click on different squares to display different colors


<style type= "Text/css" >

div {


height:122px;
width:122px;
BORDER:1PX solid;
}

</style>
<script type= "Text/javascript" >


Window.onload = function () {

}
function ChangeColor (node)
{


Node.style.background = "Red";


}

</script>
<body>
<div onclick= "ChangeColor (this);" ></div>
<div onclick= "ChangeColor (this);" ></div>
<div onclick= "ChangeColor (this);" ></div>
</body>

Event 4: Dynamically generated grid boxes


Window.onload = function ()
{

var divnode = document.getelementsbyname ("div");
for (var i = 0; i < divnode.length; i++)
{

Divnode[i].onclick = function ()
{

This.style.background = "Red";

}


}

}
</script>
<body>
<div></div>
<div></div>
<div></div>

1.javascript (Basic)

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.