.


:




:

































 

 

 

 


JavaScript




- . JavaScript.

Tip of the Day ( ). () . , .

  1. HTML
  2. JavaScript

HTML

HTML - , . DHTML (Dynamic HTML), . DHTML JavaScript ( ).

- JavaScript. script, - :

- <script>...</script>, JavaScript ( : VBScript, php, tcl/tk...).

( body), - . script head, , , .

<!-- -->

<script type="text/javascript">

</script>

JavaScript ( .js), :

<html>

<head>

<!-- -->

<script type="text/javascript"> src="http://example.com/scripts.js"></script>

</head>

...

.

JavaScript

JavaScript C/C++, Java, PHP C- . , .

var. . , .

var color = "#FFF", fsize = 1024, total_count = 0, i;

var average = null;

var c = 3;

d = 0; //!

(undefined).

,

javascript . .

. . .

var weekdays = ["", "", "", "", ""]; //

 

// Array

var myarr;

myarr = new Array(256);

 

myarr[0] = 255;

myarr[1] = 254;

 

var x = myarr[7];

- . .

// .

 

/*

.

*/

if (true | false) :

if () { 1}

[ else { 2}]

switch , . break , , .

switch () {

case 1: { 1; break;}

case 2: { 2; break;}

case 3: { 3; break;}

...

[ default: { };]

}

for. (: for , , ).

for ([ ]; []; []) { ;}

do...while. , . .

do { ;} while ()

while. , . .

while () { ;}

break continue - .

for (... in...) .

for ( in ||) { ;}

with .

with () { ;}

. . . , .

function ([ ]) {

;

[ return ;]

}

JavaScript

JavaScript , . - .

JavaScript.

Math

Math . , - . :

: E, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2.

: abs, acos, asin, atan, ceil, cos, exp, floor, log, max, min, pow, random, round, sin, sqrt, tan.

:

var r = 1.8, theta = 30, a, x, y, D;

var rnd = Math.round(Math.random()*99)+1;

 

D = Math.PI*r*r;

x = Math.max(1,7,5,9);

y = Math.pow(2,10);

 

with (Math) {

y = r*sin(theta);

x = r*cos(theta);

}

string

string ( ), , .

string :

  • : length ( ).
  • ( ): anchor (), bold ( ), charAt ( ), fixed (), fontcolor ( ), fontsize ( ), indexOf ( ), italics (), link (), substring (), toLowerCase (), toUpperCase ().

string:

var hello = "Hello, ", w = "World!";

var str = hello + w; //

 

document.write(str.bold());

document.write(str.toUpperCase());

document.write(hello.fontsize(6));

document.write(hello.substring(0,3));

 

document.write(hello.link("http://localhost"));

 

document.write(w.indexOf("l"));

 

alert("string lehgth = " + str.length);

JavaScript

JavaScript : - .

- write document. string. :

document.write("Hello, World!");

document.write("<h1>>Hello, World!</h1>"); // HTML JavaScript

 

//

document.write("<p><a href='http://localhost'>Link to localhost</a></p>");

, - alert, window. (.1), .

. 1. JavaScript

alert:

var a, b, s = "=";

 

with (Math) {

a = ceil(random()*100);

b = ceil(random()*100);

}

a > b? s = ">": s = "<"; //

 

alert("A = "+a+";\nB = "+b+";\n, A "+s+" B"); // "\n" -

:

1. . (JavaScript). .

2. JavaScript.

3. alert(). . Confirm(). . Prompt(). .

4. . Window. Document.

5. . (JavaScript).

6. , , (FOR, SWITCH, IF, WHILE, DO WHILE).

7. JavaScript. . .

8. JavaScript. . .

9. JavaScript. . .

2. JAVASCRIPT  

javascript. - (DOM) -.

CAPTCHA ( . Completely Automated Public Turing test to tell Computers and Humans Apart, ., . - ) ) , , , : . : , , . . CAPTCHA - , , , , , . .

, ( )

: javascript, , . , . , . , javascript.

  • document
  • RegExp

, . (, , ..).

input

<input> , type (.1).

1. ( type)

type
text . maxlength size ( 20 ).
password , text, (, ..).
checkbox ( ). .
hidden . . ( ).
image -. . value . src <img>.
radio . . type="radio" value, name. radio ( name) .
button . . value .
submit . , (form action="scriptname") , form. value .
reset . , .

input

  • type . text.
  • name . javascript.
  • id . -.
  • checked , checkbox radio .
  • maxlength , . .
  • size .
  • src URL, ( type="image").
  • value .

textarea

<textarea> , ( ). textarea (, , ).

, <textarea> ( ):

  • rows
  • cols

<textarea>:

<textarea rows=10 cols=50>, , .9, 448</textarea>

select

select , :

  • select .
  • select single .
  • select multiple .

select:

<select name="group">

<option>, , </option>

<option> , , </option>

<option> </option>

</select>

 

<select single name="group" size="3">

<option></option>

<option></option>

<option></option>

<option></option>

</select>

document

document , -. - , ( , , , ..). (. 1).

. 1. document

Document

, . , . .

  • title ( title);
  • fgColor bgColor ;
  • linkColor, vLinkColor, aLinkColor , ;
  • lastModified ( ) ;
  • referrer ( ) ;
  • URL, location .

- Document. , , length ( ). , , , HTML ( ):

  • Anchor () name;
  • Link () href, target;
  • Image () src, width, height.

, images, controls , ( name) ( id). , , < imgsrc ="images/cat.jpg" id ="cat_id" name ="cat_name"> n- , . img :

  1. images ( 0): window.document.images[n-1]
  2. - images ( name ):window.document.images["cat_name"]
  3. name : window.document.cat_name
  4. id getElementById: window.document.getElementById("cat_id")

Document

  • open() ; .
  • close() .
  • write() .
  • writeln() , .

write() writeln() . , , :

<script>document.write(document.lastModified);</script>

(, , .) . 2 , javascript:

2. -

OnLoad HTML
OnUnload HTML
OnClick
OnDblClick
OnMouseDown
OnMouseOver
OnMouseMove
OnMouseOut ,
OnFocus
OnBlur
OnKeyPress
OnKeyDown
OnKeyUp
OnSubmit Web-
OnReset
OnSelect
OnChange

, :

<a name="test" onClick="alert('Hello, world!');">say "Hello"</a>

, , . resetAll , <a>, onReset;

...

<script>

function resetAll() {

// do something

}

</script>

...

<a href="clear.htm" onReset="resetAll();"></a>

...

RegExp

- . javascript RegExp, .

RegExp javascript , . .., javascript.

1-6 , javascript -. .

WARNING: , javascript ( ).

1.

 

<html>

<head>

<title> </title>

<script type="text/javascript">

var maxLen = 25;

function checkMaxinput(form) {

if (form.message.value.length > maxLen)

form.message.value = form.message.value.substring(0, maxLen);

else

form.remLen.value = maxLen

form.message.value.length;

}

</script>

</head>

<body>

<form name=myform action="somehandler.cgi">

<h1> <h1>

<textarea name=message cols=28 rows=4 onKeyDown="checkMaxinput(this.form)"

onKeyUp="checkMaxinput(this.form)"></textarea>

<p> <input readonly type=text name=remLen size=3 value="25"> </p>

</form>

</body>

</html>

2.

<html>

<head>

<title>

</title>

<SCRIPT type="text/javascript">

function checkIt(){

var t0=document.getElementById('first').value;

var t1=document.getElementById('second').value;

if (t0 == "" || t0 == "") {

alert(" !"); return false;

}

if (t1 == "") {

alert(" !");

return false;

}

return true;

</SCRIPT>

</head>

<body>

<form method='get' action='somescript.php'>

<input id="first" type="text" size=60px value=''>

<br>

<textarea id="second" rows=4 cols=60></textarea>

<br>

<input type='submit' onClick="if (!checkIt()){return false;}" value="">

</form>

</body>

</html>

3. ( window)

<html>

<head>

<title>/ </title>

</head>

<body>

<p><a name="demoOpen" onClick="mywindow = window.open('window.htm','mywin','height=120, width=300, left=100, top=30');"></a>

<a name="demoClose" onClick="mywindow.window.close();"></a>

</body>

</html>

4.

<html>

<HEAD>

<TITLE> </TITLE>

</head>

<BODY>

<p onClick="fgColor='#3CB094';bgColor='#FFFF00';">CLICK 4 REDRAW</p>

</BODY>

</HTML>

5. ( Date)

<html>

<HEAD>

<TITLE>, </TITLE>

<script type="text/javascript">

function fulltime() {

var time=new Date();

document.clock.full.value=time.toLocaleString(); // 1-

document.getElementById("jsclock").innerHTML=time.toLocaleString(); // 2-

setTimeout('fulltime()',500) }

</script>

</head>

<body>

<form name=clock>

<input type=text size=20 name=full><!-- 1- -->

<span id="jsclock"></span><!-- 2- -->

</form>

<script type="text/javascript"> fulltime(); </script>

</BODY>

</HTML>

6. ( navigator)

 

<HTML>

<HEAD>

<TITLE> </TITLE>

</HEAD>

<BODY>

<h1> Web :</h1>

<ul>

<SCRIPT type="text/javascript">

document.write("<li> :<b>"+navigator.appName+"</b>");

document.write("<li>:<b>"+navigator.appVersion+"</b>");

document.write("<li> :<b>"+navigator.userAgent+"</b>");

document.write("<li>: <b>"+navigator.platform+"</b>");

</SCRIPT>

</ul>

</BODY>

</HTML>

 

:

  1. JavaScript. , , . , , JavaScript.
  2. . JavaScript
  3. - , , . JavaScript




:


: 2016-03-26; !; : 1606 |


:

:

, ; , .
==> ...

1932 - | 1720 -


© 2015-2024 lektsii.org - -

: 0.243 .