First, JS Foundation
Js-javascript
1, JS function:
1), the operation of the data. 2), control some functions of the browser. 3), control elements (attribute, content, style)
JS Reference Location:
Can be placed anywhere in the HTML page.
Recommended to be placed behind
You can also put it in a file that ends in JS and reference the file to an HTML page.
2. Format:
<script type= "Text/javascript" >
JS Code
</script>
1. Alert ("") warning dialog box.
2, confirm ("") determine the dialog box, pop up a selection of the OK dialog box, click OK to return True. Clicking Cancel will return False.
3. Prompt ("Content displayed in dialog box") pops up a dialog box that allows you to enter content.
3. Basic data type:
String, Decimal, Integer, Time-Date, Boolean
4. Variables:
are generic type var
5. Type conversion:
Other types are converted to integers: parseint ();
Other types converted to decimals: parsefloat ();
Determine if it is a numeric type: IsNaN (); is a number then returns false, not a number that returns true;
6, operators, if statements, for loops, and C #.
7. Array:
Definition of the array: new Array ();
Assignment value: a[0]=123; a[1]= "haha";
Value: A[i];
8. Functions
Define functions: Functionaaa () {function Body}; AAA is the name of the function
Calling function: AAA ();
9. Exercises:
1. Let the user enter a number, return "is a number", "not a number"
1 <script type= "Text/javascript" >2 var a = prompt ("Please enter a number:"); 3 if (IsNaN (a) = =false) 4 Alert ("Enter a number!") ")5 else6 alert (" Input is not a number! ") ")7 </script>
2. Let the user enter 5 student information, name, gender, age, score.
Print the full information of the student with the highest scores, in the following format:
"Name: xxx, sex: xxx, age xxx, score: XXX, first place! ”
1<script type= "Text/javascript" >2 varArrall =NewArray ();3 4 for(vari = 0; I < 3; i++) {5 vararr =NewArray ();6Arr[0] = prompt ((i + 1) + "Please enter your name:");7Arr[1] = prompt ((i + 1) + "Please enter Gender:");8Arr[2] = prompt ((i + 1) + "Please enter Age:");9Arr[3] = prompt ((i + 1) + "Please enter your score:");Ten OneArrall[i] =arr; A } - - for(vari = 0; i < arrall.length; i++) { the for(varj = i + 1; J < Arrall.length; J + +) { - if(Arrall[i][3] < arrall[j][3]) { - varZhong =Arrall[i]; -Arrall[i] =Arrall[j]; +ARRALL[J] =Zhong; - } + } A } at -Alert (' Name: ' + arrall[0][0] + ', Gender: ' + arrall[0][1] + ', Age: ' + arrall[0][2] + ', score: ' + arrall[0][3] + ', first place! ‘); - -</script>
DOM Operations
var Aaa=document.getelementbyid ("id")
Put this xx found by ID into AAA
Events: Actions
"Click event": aaa.onclick=function () {
function body
}
Click the event to put the method behind.
1. Windows object Operations
(1) window.open ("Part I", "Part II", "Part Three", "Part IV")
The first part write the page address
The second part writes the page opens the way: _self opens in itself; _blank opens in a new blank page
The third part controls the open Window format: width=100 height=100 left=200 top=200 New open window Broadband 100 height 100 distance left 200 distance Top 200
window.open () is a return value that can be stored in a variable: var aaa=window.open ();
You can save multiple open windows in an array w:
function Openw ()
{
W[i++]=window.open ();
}
(2) Window.close (); Close the current window.
Close the source window that opens the current window: Window.opener.close ();
Adjust page:window.scrollto (x, y) scrolls the page to a location and y represents a portrait scroll. in general, X is 0, adjusting the Y value, acting like an anchor.
2. Window.history Object
Window.history.back (); page back
Window.history.forward (); page forward
Window.history.go (n); n if a positive number represents a forward n page, n is a negative number that represents a backward N page.
3. Window.location Object
var s=window.location.href; Get the current page address
window.location.href= "Path"; Change page address, will jump page
"2017-03-28" JS Foundation, Windows object, History object, Location object