.


:




:

































 

 

 

 


JavaScript HTML-. JavaScript , <script> </script>




JavaScript , <script> </script>. , . HTML. js.

<script type="text/javascript" src="/jspr/pr.js"></script>

/jspr/ pr.js, JavaScript <script> </script>.

HTML. . , . :

<!-- -->

<html> <body>

<form>

<input type="button" value="click me"

onclick="window.alert(' Hello!')">

</form>

<a href="pr3.htm" onclick="alert('Links clicked')">

click me</a>

</body>

</html>

, "Browser"

<!-- pr15: -->

<html> <head>

<title>Test of Browser name</title>

</head>

<body>

<h1 align=center> </h1>

<P><hr>

<form name=fr>

<input type=button name=browser value=Browser

onClick= "alert(window.navigator.appName+navigator.appVersion)">

</form>

</body> </html>

navigator.appName navigator.appVersion

1. JavaScript:

1. html-. !

c document.write(). "Hello World" alert (string) confirm((string).

2.

<!--This is a comment-->

//This is a comment

/*This comment has more than one line*/

3. , ( prompt()) ( ), . , . document.write("str");. , .

promt() , OK CANCEL. , OK, null, CANCEL.

4. OnClick , confirm() " !".

5. JavaScript, Web- <h1 > .

6. <p> , .

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title> !</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

<script type="text/javascript">

window['username'] = false;

function action() {

confirm(' !');

 

}

function sayAgain() {

alert(' !')

}

function writeHello() {

var str = prompt(' ', '');

if (str) {

var newEl = document.createElement('h1');

newEl.innerHTML = str;

document.getElementById('strings').appendChild(newEl);

}

}

function createPTag() {

var newEl = document.createElement('p');

newEl.innerHTML = ' , !!!';

document.getElementById('strings').appendChild(newEl);

}

</script>

</head>

<body onload="action()">

<div id="strings"></div>

<input type="button" onclick="sayAgain()" value=" " />

<input type="button" onclick="writeHello()" value=" " />

<input type="button" onclick="createPTag()" value=" " />

</body>

</html>

 

7. , ( ) , .

if else;

?:;

switch.

parseInt .

8. , ( ) , 1 , 1000.

for;

while;

do while

if()

9. : ""; ""; ""; ""; ""; " ".

 

.

<html>

<head>

<title>JavaScript </title>

<script language="JavaScript">

var msg = document.title;

var c = 0;

function animateTitle()

{

document.title = msg.substring(0,c);

if(c == msg.length)

{

c = 0;

setTimeout("animateTitle()", 2000)

}

else

{

c++;

setTimeout("animateTitle()", 200)

}

}

animateTitle()

</script>

</head>

<body>

<h1> </h1>

</body>

</html>

 

<html>

<head>

<title>JavaScript </title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script type="text/javascript">

var msg = document.title;

var c = 0;

var strings = new Array("", "", "", "", "", " ");

function animateTitle()

{

document.title = strings[c];

if(c == strings.length - 1)

{

c = 0;

setTimeout("animateTitle()", 2000)

}

else

{

c++;

setTimeout("animateTitle()", 200)

}

}

</script>

</head>

<body onload="animateTitle()">

<div id="strings"></div>

</body>

</html>

status bar , ( , , ..). JavaScript :

window.status ;

window.defaultStatus .

status . defaultStatus . :

window.status = "put your message here"

a) JavaScript, , Web-.

b) .

c) . ', !' ( onMouseOver), ', ' ( onMouseOut).

d) Web-

e)

.

<HTML>

<HEAD>

<SCRIPT>

function time_scroll()

{

var d = new Date();

window.status = d.getHours()

+ ':' + d.getMinutes()

+ ':' + d.getSeconds();

setTimeout('time_scroll()',1000);

}

</SCRIPT>

</HEAD>

<BODY onLoad="time_scroll()">

<H1> </H1>

</BODY>

</HTML>

setTimeout() , ( ), :

idt = setTimeout("JavaScript_",Time);

Mozilla , : -> -> JavaScript -> -> .

10. :

a) , , ;

b) , , . 9.00 17.00. : , , , , , 12.00 12.30.

JavaScript.

Date(), .

time=new Date();

, , ,

alert (Date());

, , ..

getSeconds() - 0 59;

getMinutes() - 0 59;

getHours() - 0 23;

getDay() - 0 6 (0->, 1 -> , ..);

getDate() - 1 31;

getMonth() - 0 11;

getFullYear() - , 1970.


,

time=new Date();

time_sec=time.getSeconds();//

time_min=time.getMinutes();//

time_hours=time.getHours();//

getSeconds(), getMinutes() getHours() 10, 0 .

function wr_hours()

{

time=new Date();

time_sec=time.getSeconds();

time_min=time.getMinutes();

time_hours=time.getHours();

time_wr=((time_hours<10)?"0":"")+time_hours;

time_wr+=":";

time_wr+=((time_min<10)?"0":"")+time_min;

time_wr+=":";

time_wr+=((time_sec<10)?"0":"")+time_sec;

}

. document.write() , . innerHTML, HTML-. HTML- . . , HTML-, , , , -. . span, hours. JavaScript

obj_hours=document.getElementById("hours")

<span id="hours"></span>

<script type="text/javascript">

obj_hours=document.getElementById("hours");

function wr_hours(){

time=new Date();

time_sec=time.getSeconds();

time_min=time.getMinutes();

time_hours=time.getHours();

time_wr=((time_hours<10)?"0":"")+time_hours;

time_wr+=":";

time_wr+=((time_min<10)?"0":"")+time_min;

time_wr+=":";

time_wr+=((time_sec<10)?"0":"")+time_sec;

obj_hours.innerHTML=time_wr;

}

wr_hours();

</script>

, , wr_hours() . setInterval(), . .

setInterval("{}", { });

(1000 ). , .

<span id="hours"></span>

<script type="text/javascript">

obj_hours=document.getElementById("hours");

function wr_hours()

{

time=new Date();

 

time_sec=time.getSeconds();

time_min=time.getMinutes();

time_hours=time.getHours();

time_wr=((time_hours<10)?"0":"")+time_hours;

time_wr+=":";

time_wr+=((time_min<10)?"0":"")+time_min;

time_wr+=":";

time_wr+=((time_sec<10)?"0":"")+time_sec;

obj_hours.innerHTML=time_wr;

}

wr_hours();

setInterval("wr_hours();",1000);

</script>

. getDay() getMonth() , , .

name_month=new Array ("","","", "","", "","","", "","", "","");

name_day=new Array ("","","", "","", "","");

<html>

<head>

<title> JavaScript</title>

</head>

<body>

<h1> JavaScript</h1>

<div><span id="hours"></span>

</div>

<script type="text/javascript">

obj_hours=document.getElementById("hours");

name_month=new Array ("","","", "","", "","","","", "","","");

name_day=new Array ("","", "","","", "","");

function wr_hours()

{

time=new Date();

time_sec=time.getSeconds();

time_min=time.getMinutes();

time_hours=time.getHours();

time_wr=((time_hours<10)?"0":"")+time_hours;

time_wr+=":";

time_wr+=((time_min<10)?"0":"")+time_min;

time_wr+=":";

time_wr+=((time_sec<10)?"0":"")+time_sec;

time_wr=" "+name_day[time.getDay()]+", "+time.getDate()+" "+name_month[time.getMonth()]+" "+time.getFullYear()+" . "+time_wr;

obj_hours.innerHTML=time_wr;

}

wr_hours();

setInterval("wr_hours();",1000);

</script>

</body>

</html>

"" .

11. . , , . : 2 , , .

<html>

<head>

<title> </title>

 

<script type="text/javascript">

 

var delay = 50; //

var pos = 0;

//,

var msg = ' ';

// ,

function printWords(text, dir)

{

var typingtext = text.substring(0, pos);

document.getElementById("type").innerHTML = typingtext;

pos += dir; //

if (pos > text.length)

setTimeout('printWords("'+text+'",'+(-dir)+')', delay * 50);

else

{

if(pos < 0)

{

 

dir = -dir;

}

setTimeout('printWords("'+text+'",'+dir+')', delay);

}

}

</script>

 

</head>

<body onLoad="printWords(msg, 1)">

 

<h1> </h1>

 

<div id="type"></div>

 

</body>

</html>

 

12. body , , prompt ().

<html> <head>

<script type=text/javascript">

function askName() {

var name = prompt ("What is your name, please?11,"")

return name

}

</script>

</head>

<body>

<script type="text/javascript">.

document.write("Welcome to my web page, " + askName() + ".")

</script>

</body>

</html>

onclick .

 





:


: 2016-07-29; !; : 1197 |


:

:

,
==> ...

1734 - | 1673 -


© 2015-2024 lektsii.org - -

: 0.126 .