Professional Documents
Culture Documents
JavaScript
-
HTML
JavaScript
Client-Side JavaScript :
Server-Side JavaScript : (
JavaScript
JavaScript 3
1. body
2. head
3.
JavaScript
1. body
<html>
<head></head>
<body>
<script type="text/javascript">document.write
("This message is written by JavaScript");
</script>
</body>
</html
JavaScript
2. head
<html><head>
<script type="text/javascript">
function message(){
alert("This alert box was called with the onloadevent");
}
</script>
</head>
<body onload="message()">
..
</body></html>
JavaScript
3.
<html><head>
<script type="text/javascript" src="xxx.js">
</script>
</head>
<body>
..
</body>
</html>
Var ;
Var = ;
=
1. num = 500
2. (True) (False) test = True;
3. ("...") name = "Adisak";
+, -, x, /
&&, ||, ! AND, OR NOT
1. if statement
if(condition) <script type="text/javascript">
{ var d=new Date();
code to be executed if condition is var time=d.getHours();
true if (time>12) {
} document.write("<b>Good
morning</b>");
}
</script>
2. if..else statement
if (condition) { <script type="text/javascript">
code to be executed if condition is true } var d=new Date();
else var time=d.getHours();
{ if (time>12) {
code to be executed if condition is not document.write("<b>Good
true morning</b>");
} } else {
document.write("<b>Good day</b>");
}
</script>
3. if..else if..else statement
if (condition1) <script type="text/javascript">
{ var d=new Date();
code to be executed if condition1 is var time=d.getHours();
true if (time>12) {
} else if (condition2) { document.write("<b>Good
code to be executed if condition2 is morning</b>");
true } else if (time<12 && time <18) {
} else { document.write("<b>Good afternoon</b>");
code to be executed if condition1 and } else {
condition2 are not true document.write("<b>Good evenning</b>");
} }
</script>
4. switch statement
switch(n) {
case 1:
execute code block 1
break;
case 2:
execute code block 2
break;
default:
code to be executed if n is different from case 1 and 2
}
1. 2
Standard Function
User-defined Function
2.
= ();
3.
(1, 2, ...)
{
...........................................
.......................................... }
function name
parameter (arguement)
statements
4.
<HEAD>
<BODY>
JavaScript
Event JavaScript
function function event
event ,
, submit
JavaScript
1. onFocus, onBlur onChange
<input type="text" size="30" id="email"
onchange="checkEmail()">
email
checkMail()
JavaScript
2. onSubmit
onSubmit validate
<form method="post" action="xxx.htm" onsubmit="return checkForm()">
JavaScript
3. onMouseOver onMouseOut
onMouseOver onMouseOut