JavaScript (2) 1
JavaScript 1.! 1. 2. 3. DOM 4. 2. 3. Ajax Shelley Powers,, JavaScript David Flanagan, JavaScript 2
(1) var a; a = 8; a = 3 + 4; a = 8 3; a = 8 * 2; a = 8 / 2; a = 8 % 3; 1 a++; ++a; (++ var b = ++a; b a+1 var b = a++ b a ) 1 a--; --a; var b = -a; a += 8; a -= 3; a *= 4; a /= 2; a = a + 8; a = a 3; a = a * 4; a = a / 2; 3
(2) if( ) { A } else { B } A B if( 1) { A } else if ( 2) { B } else if( 3) { C } else { D } 1 A 2 B 3 C D switch( ) { case 1: A [break;] case 2: B [ break;] default: C } 1 A 2 B C break A B C 4
(3) while( ) { A } A do { A } while( ) A A for( A; ; B){ C } 1. A 2. C 3. B 2 for( in ) {.. } 5
(4) if (a == 3) # if( a = 3 ) if ( a!= 3) if ( a > 3 ) if ( a < 3) if( a >= 3) if( a <= 3) AND if ( (a > 3) && (a < 10) ) OR if( (a <3) (a > 10)) if(!(a < 3)) 6
(true, false) const HOGE = 3; null ( ) document.writeln(b); If( x ) (=null ) undefined ( undefined ) var a; document.writeln(a); 7
( ) function plus(x, y) { return x + y; } document.writeln(plus(3, 4)); ( ) var f = function(x, y) { return x + y; } document.writeln(f(5,6)); ) var f = new Function( x, y, return x + y ); document.writeln(f(7,8)); 8
var a = new Array( one, two ); var a = [ one, two ]; a.push( three ); var elem = a.pop(); // Var len = a.length(); // var arr = [ a, b, c, d, e ]; shift unshift a b c d e push pop 9
JavaScript JavaScript var edic = new Object(); edic[ orange ] = ; edic[ apple ] = ; document.writeln(edic[ orange ]); var jdic = new Object(); jdic[ ] = orange ; jdic[ ] = apple ; var edic = { orange :, apple : }; document.writeln(edic.orange); 10
var point = new Object(); point.x = 100; point.y = 200; point.move = function(newx, newy) { this.x = newx; this.y = newy; } point.move(300,400); (= ) move this (= ) 11
(1) JavaScript 12
(2) function Point(x, y) { this.x = x; this.y = y; this.move = function(newx, newy) { this.x = newx; this.y = newy; }; } var p = new Point(3, 4); move Point.prototype.move = function(newx, newy) { this.x = newx; this.y = newy; }; 1 13
14
DOM 15
( ) ( ) 16
<head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <script type="text/javascript"> document.onmousemove = mousemove; function mousemove(evnt) { var x = parseint(evnt.clientx); var y = parseint(evnt.clienty); var screen = document.getelementbyid("screen"); screen.innerhtml="x: "+x+" y: "+y; } </script> </head> <body> <div id="screen"></div> </body> 17
DOM var screen = document.getelementbyid( screen ); var scrsty = screen.style; scrsty.position= absolute ; scrsty.top=100 + px ; sctsty.left=200+ px ; 18
var amount = 0; function changeamount(x) { document.getelementbyid("inputscreen").value=x; amount = x; } </script> </head> <body onload="changeamount(0)"> <form> <input type="text" width="20" id="inputscreen"/><br/> <input type="button" value="7" onclick="changeamount(10*amount+7)"/> <input type="button" value="8" onclick="changeamount(10*amount+8)"/> <input type="button" value="9" onclick="changeamount(10*amount+9)"/> <br/> <input type="button" value="4" onclick="changeamount(10*amount+4)"/> <input type="button" value="5" onclick="changeamount(10*amount+5)"/> <input type="button" value="6" onclick="changeamount(10*amount+6)"/> <br/> <input type="button" value="1" onclick="changeamount(10*amount+1)"/> <input type="button" value="2" onclick="changeamount(10*amount+2)"/> <input type="button" value="3" onclick="changeamount(10*amount+3)"/> <br/> <input type="button" value="0" onclick="changeamount(10*amount)"/> <input type="button" value="c" onclick="changeamount(0)"/> <input type="button" value="d" onclick="changeamount(math.floor(amount/10+0.01))"/> </form> 19
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> </head> <body> <script type="text/javascript"> </script> </body> </html> 20