JavaScript enhances Ajax Fundamentals

Source: Internet
Author: User

<TITLE>JS type </title>
<meta http-equiv= "content-type" content= "text/html; Charset=utf-8 ">
<body>

<script type= "text/javascript" >
num is number type
var num = 100;
STR is a string type, note that the string type in JS "or" can be
var str = "haha";
Flag is a Boolean type
var flag = true;
</script>

<script type= "text/javascript" >
Content in multiple script blocks that can be accessed by each other
Alert (flag);
var person = null;
var card;
Alert (card);
Undefined is not a string, it is a type, if you want to determine if a variable is undefined,
Judging by the following code:
if (card = = Undefined) {
Alert ("card variable has no value");
}else{
Alert (card);
}
</script>

There are three ways to define functions in <title>js </title>
<meta http-equiv= "content-type" content= "text/html; Charset=utf-8 ">
<body>

<script type= "text/javascript" >
/* Normal Mode (first)
function Add (num1,num2) {
return NUM1 + num2;
}
Window.alert ("10+20=" + Add (10,20));
*/
</script>

<script type= "text/javascript" >
/* constructor mode, The last parameter is the function body, each parameter is a string type (after)
var add = new Function ("num1", "num2", "return num1+num2");
Window.alert ("100+200=" + Add (100,200));
*/
</script>

<script type= "text/javascript" >
/* Direct volume or anonymous or nameless way (again)
var add = function (num1,num2) {
return NUM1 + num2;
}
Window.alert ("1000+2000=" + Add (1000,2000));
*/
</script>

There are four kinds of objects in <title>js </title>
<meta http-equiv= "content-type" content= "text/html; Charset=utf-8 ">
<body>


<script type= "text/javascript" >

Date
var nowstr = new Date (). tolocalestring ();
Window.document.write (nowstr + "<br/>");


Math
For (var I=1;i<=10;i++) {
Random integers from 1 to 9
document.write (math.floor (math.random () *9) +1 + "<br/>");
//}


String
var str = "hello hi";
var size = str.length;
Alert (SIZE);//7


Array
var array = new array ("language", "math", "english", true,123);
For (var I=0;i<array.length;i++) {
document.write (array[i] + "");
//}

</script>

<script type= "text/javascript" >
/* Custom Objects
function Person (id,name,sal) {
This.id = id;
THIS.name = name;
This.sal = sal;
}
var p = new Person (1, "bobo", 7000);
document.write ("number:" + p.id + "<br/>");
document.write ("name:" + p.name + "<br/>");
document.write ("salary:" + p.sal + "<br/>");
*/
</script>

<script type= "text/javascript" >
Window object, opening new windows
var url = "04_images.html";
window.open (url);
</script>

<script type= "text/javascript" >
Status object, Setting the current time to the status bar
var nowstr = new Date (). tolocalestring ();
Window.status = nowstr;
</script>

<script type= "text/javascript" >
Location object that simulates the user entering a URL in the address bar to access other pages
var url = "04_images.html";
Window.location.href = url;
</script>

<script type= "text/javascript" >
History object, Presentation Refresh
Window.history.go (0);
</script>

<form action= "04_images.html" method= "POST" >
<input type= "button" value= "submit"/>
</form>

<!--demo with JS submission form, important--
<script type= "text/javascript" >
Position Submit button
var inputelement = document.getElementsByTagName ("input") [0];
Add a click event for the Submit button
Inputelement.onclick = function () {
Positioning <form> labeling, forms represents a collection of all forms in a document object, referencing different forms by subscript, starting with 0
var formelement = document.forms[0];
Submit the form to the location specified by the Action property
Formelement.submit ();
}


</script>

JavaScript enhances Ajax Fundamentals

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.