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)