Professional Documents
Culture Documents
தமிழில
JavaScript
த.நதியா
nithyadurai87@gmail.com
மன்னூில
வவெளயீடு :
கணிியம
அறகககட்டளள
kaniyam.com
அகடடள்ப்ப்ம,
மன்னூலாககம :
பிரசன்னா
udpmprasanna@gmail.com
உரிடளமை :
Creative Commons Attribution -
ShareAlike 4.0 International
License.
http://kaniyam.com/learn-javascript-in-tamil
என்ற மகவெரியிில இருந்த இந்த நூடளல
பதிவிறககம வசய்ியலாம. உஙகள
கருததகடளளயும இஙறக பகிரலாம.
த.சீனிவொசன்
tshrinivasan@gmail.com
ஆசரிியர்
கணிியம
editor@kaniyam.com
உரிடளமை
நூில மூலம :
http://static.kaniyam.com/ebooks/Learn-
Javascript-in-Tamil.odt
மன்னஞ்சில:
nithyadurai87@gmail.com
வெடளல பதிவு:
http://nithyashrinivasan.wordpress.com
உதாரணஙகள
ஆசரிியர் உடளர................................................10
உதாரணஙகள.................................................13
1 JavaScript...................................................23
JavaScript – அிமகம...................................24
..................................................................26
Variables...................................................32
Variable Declaration & Initialization...33
Reserved Words...................................40
..................................................................42
3 Operators...................................................43
Arithmetic Operators............................48
Comparison Operators........................49
..............................................................50
Assignment Operators..........................52
Miscellaneous Operator......................53
4 Conditional and Looping Statements in
javascript........................................................55
Conditional statements..............................55
If…Else................................................56
Switch Case..........................................59
5 Looping statements.....................................63
For loop.....................................................67
Break…Continue......................................71
Events...................................................85
7 Window-வின் பணபுகள..............................91
location.................................................91
Print.....................................................95
Dialog Boxes.............................................98
alert():................................................103
confirm():...........................................104
............................................................105
prompt():............................................105
9 Exception Handling.................................108
10 Form Validations, Javascript Objects &
Animations...................................................117
தகவெிலகடளள றசாதிததில...........................117
Object:.....................................................132
Encapsulation:.........................................134
Inheritance:.............................................135
Polymorphism:........................................136
.....................................................................138
12 Javascript Objects...................................139
13 Animation...............................................150
சாதாரண வவெளப்பாடு:...........................170
கணிியம அறகககட்டளள................................233
(Sample.html)
<html>
<body>
<script
language="javascript"
type="text/javascript">
<!--
_______________________________________________
__________________________________________
Variables
Javascript-ில உளள variable-ஆனத மதில
நடளலத தரவு வெடளககளான (primitive data
types) எணகள, எுததககள மைற்றும ‘true’ ,
‘false’ என்பத றபான்ற Boolean மைதிப்புகடளள
றசமககும வெிலலடளமை வகாண்த. றமைலும Null
மைற்றும undefined என்பத றபான்ற பிற நடளலத
தரவு வெடளககடளளயும இத ஆதரிககும.
Variable Declaration &
Initialization
Javascript-ில உளள ஒரு variable-ஆனத
எுததககள, எணகள மைற்றும தசமை எணகள
றபான்ற அடளனதத விதமைான தரவுகடளளயும
தானாகறவெ அடள்ியாளம கணடு வகாளளம. பிற
வமைாிழகளில குிப்பிடுவெத றபான்று int, flot,
string என்வறிலலாம வவெளப்படள்ியாக்
வசாிலலத றதடளவெயிிலடளல.
உதாரணம:
<html>
<body>
<script type =
"text/javascript">
<!--
var salary;
salary="25000.00";
var age = 29,
name='Nithya';
document.write(salary,"<br/>",
name,"-",age)
//-->
</script>
</body>
</html>
<html>
<body onload =
checkscope();>
<script
type="text/javascript">
<!--
var
salary=25000.00;
document.write(salary);
function
checkscope( )
{
var salary =
"50000.00";
document.write(salary);
}
//-->
</script>
</body>
</html>
Reserved Words
ஒரு சல வொர்தடளதகடளள (eg: export, final,
long) நனமமைாில variable-ஆக அிவிகக
மடியாத. ஏவனன்றாில இத றபான்ற
வொர்தடளதகளககு என்வனன்ன மைதிப்புகள
என்படளத javascript-ஐ உருவொககிியவெர்கறள
நியமதத விகட்னர். அடளவெறிய ‘Reserved
Keywords’ எனப்படும. இதன் பகடடியில
பின்வெருமைாறு:
default if return
do import static
double in super
3 Operators
<html>
<body>
<script
type="text/javascript">
<!--
var a = 100;
var b = 40;
document.write("Arithmetic -
");
document.write(a
%b);
document.write("<br />");
document.write("Comparison -
");
document.write(a<b);
document.write("<br />");
document.write("Logical - ");
document.write(((b<=100)&&(a>=
100)));
document.write("<br />");
document.write("Conditional -
");
document.write((a
> b) ? a : b);
document.write("<br />");
document.write("typeof - ");
document.write(typeof
a=="string" ? "The value is
string" : "The value is not a
string");
document.write("<br />");
document.write("Assignment -
");
document.write((a
-= b));
document.write("<br />");
//-->
</script>
</body>
</html>
Arithmetic Operators
இதன் கீழ வெரும கூகட்ில, கிழதில, வபருககில,
வெகுததில என்வனன்ன வசய்யும என்பத
உஙகளகறக வதரியும. இதனு்ன் றசர்தத
Modulus (%), Increment( ++), Decrement (–)
எனும 3 வெடளக குியீடுகள உளளன. % என்பத
இரணடு எணகடளள வெகுததில கிடள்ககும
மீதிடளிய வவெளப்படுததம. ++ என்பத
வகாடுககப்பகட் எணணு்ன் ஒரு எணடளணக
கூகடடயும, — என்பத வகாடுககப்பகட்
எணணு்ன் ஒரு எணடளணக கிழததம
வவெளப்படுததம.
Comparison Operators
இரணடு எணகடளள ஒப்பிகடடு அவெற்றுககுள எத
வபரிியத ( >), சிியத (<), சமைமைானத (==),
சமைமிலலாதத (!=), என்பத றபான்ற
தகவெிலகடளள வவெளப்படுதத உதவும. (>=)
என்பத சமைமைானத அிலலத வபரிியத என்றும,
(<=) என்பத சமைமைானத அிலலத சிியத
என்றும வபாருளபடும. இதன் வவெளப்பாடு
எப்றபாதம உணடளமை (true), வபாய் ( false)
எனும இரணடு மைதிப்புகடளளறிய வபற்ிருககும.
Logical (or Relational) Operators
இத உணடளமை, வபாய் எனும 2 மைதிப்புகடளள
ஒப்பீடு வசய்ியப் பியன்படுகிறத. &&
ஒப்பி்ப்படுகின்ற அடளனததம உணடளமை
என்படளத வவெளப்படுததினாில மைகடடுறமை,
இதவும உணடளமை என்படளத வவெளப்படுததம. !!
ஒப்பி்ப்படுபடளவெகளில ஏறதனும ஒன்ின்
வவெளப்பாடு உணடளமை என்று இருந்தாில கூ்
இதவும உணடளமை என்படளத வவெளப்படுததி
விடும. ! என்பத வவெளப்படும விடள்
உணடளமைியாக இருப்பின் வபாய் என்றும,
வபாய்ியாக இருப்பின் உணடளமை என்றும மைாற்ி
வவெளப்படுததம.
Assignment Operators
= என்பத வெலப்புறம இருககும மைதிப்பிடளன,
இ்ப்புறம உளள variable-ககு வெழைஙகிவிடும.
b=40 என்று ஒரு variable காணப்படன், a=b
எனக வகாடுககுமறபாத, a-ன் மைதிப்பு 40 என
மைாிவிடும. பின்னர் a+=b எனக
வகாடுககுமறபாத, ஏற்கனறவெ a-ில உளள 40
எனும மைதிப்பு, b-ில உளள 40-வு்ன்
கூகட்ப்பகடடு a-ன் மைதிப்பு 80 என மைாிவிடும.
a-=b எனக வகாடுககுமறபாத 80-லிருந்த 40
கிழககப்பகடடு மீணடும a-ன் மைதிப்பு 40-கறக
வெந்தவிடும. இப்றபாத பின்வெரும
உதாரணதடளதப் பார்ததாில உஙகளாறலறிய
புரிந்த வகாளள மடயும.
Miscellaneous Operator
Conditional (or ternary) Operators (a > b) ? a :
b என்பத ஒரு றசாதடளனடளிய வசய்த, அதன்
வவெளீிப்பாடு உணடளமை என இருப்பின், ?-ககு
அடுதத உளள மைதிப்பிடளனயும, வபாய் என
இருப்பின் அந்த மைதிப்பிற்கு அடுதத உளள
மைதிப்பிடளனயும வவெளப்படுததம.
Conditional statements
ஒரு variable-ில றசமககப்பகடடுளள
மைதிப்பானத பிலறவெறு நபந்தடளனகறளாடு
ஒப்பி்ப்படும. ஒவ்வவொரு நபந்தடளனயும
பிலறவெறு வெடளகியான நகழவுகடளளக
வகாணடருககும. ஒப்பி்ப்படுகின்ற
மைதிப்பானத எந்த நபந்தடளனறியாடு
ஒததப்றபாகிறறதா, அதனுடள்ிய நகழவிடளன
நகழததம வசியலுககு If…Else மைற்றும
switch_case றபான்ற conditional statements
பியன்படுகின்றன.
If…Else
பின்வெரும உதாரணததிில age எனும variable-ில
உளள மைதிப்பு 18 மதில 21 வெடளர இருப்பின்
"Legally fit for marriage” எனும
வொககிியதடளதயும, 21-ஐ வி் அதிகமைாக
இருந்தாில "Legally and Medically fit” எனும
வொககிியதடளதயும, றவெறு எந்த மைதிப்பாக
இருந்தாலும "Not fit for marriage” எனும
வொககிியதடளதயும வவெளப்படுததமைாறு
வகாடுககப்பகடடுளளத.
ஒரு If…Else றசாதடளனயிில எப்றபாதம if, else
if, else எனும 3 வெடளகியான றசாதடளனகடளள
ககட்ாியம வகாடுகக றவெணடும என்று
அவெசியமிலடளல. If மைகடடுறமை வகாடுதத ஒரு
றசாதடளனயு்ன் நறுததிகவகாளளலாம. If-
வு்ன் றசர்தத Else-ஐயும வகாடுதத இரணடு
றசாதடளனயு்ன் நறுததிகவகாளளலாம.
பிலறவெறு றசாதடளனகடளள நகழதத
விருமபினாில else if -மூலம றவெணடிய
எணணிகடளகயிில றசாதடளனகடளள
றசர்ததகவகாணற்யும வசிலலலாம.
<html>
<body>
<script
type="text/javascript">
<!--
var age = 24;
if((age >= 18) &&
(age <= 21))
{document.write("Legally fit
for marriage");}
else if( age >
21 ){document.write("Legally
and Medically fit for
marriage");}
else{document.write("Not fit
for marriage");}
//-->
</script>
</body>
</html>
<html>
<body>
<script
type="text/javascript">
<!--
var grade='II';
switch (grade)
{
case 'I':
document.write("Good
job");break;
case 'II':
document.write("Pretty
good");break;
case 'III':
document.write("Passed");br
eak;
case 'IV':
document.write("Not so
good");break;
case 'V':
document.write("Failed");br
eak;
default:
document.write("Grade is
not valid")
}
//-->
</script>
</body>
</html>
இதன் Output பின்வெருமைாறு:
5 Looping statements
<html>
<body>
<script
type="text/javascript">
<!--
var x = 0;
var y = 0;
do{document.write(y);y++;}
while (y < 5);
//-->
</script>
</body>
</html>
For loop
For loop- ம while றபான்றறத. இதன் வெடவெம
மைகடடுறமை மைாறுபகடடுளளத. ஒறர ஒரு
விததிியாசம என்னவவெனிில, loop-ககுள
variable-ன் தவெகக மைதிப்பு
வெடளரியறுககப்படுகிறத. கீழககண்
எடுததககாகடடில for loop- ஆனத x-ன் மைதிப்பு
0 என்றும, அத 10-ககும குடளறவொக (x<10)
இருககும வெடளர அடள்ப்புக குிககுள { }
உளளவெற்டளற வசியிலபடுதத றவெணடும எனவும,
ஒவ்வவொரு மடளறயும தவெகக மைதிப்பு்ன் 1
கூகட்ப்ப் றவெணடும (x++) எனவும
கூறுகிறத.
<html>
<body>
<script
type="text/javascript">
<!--
var x;
document.write("<br />");
for (x in
navigator)
{document.write(x+"<br />");}
//-->
</script>
</body>
</html>
<html>
<body>
<script
type="text/javascript">
<!--
var x = 1;
var y = 1;
while (x < 10)
{
if (x == 5)
{break;}
x = x + 1;
document.write(
x + "<br />");
}
document.write("<br />");
if (y == 5)
{continue;}
document.write(y);
}
document.write("<br />");
Heading:
for (var i = 0; i
< 3; i++)
{
document.write(i + "times"
+ "<br />");
for (var j = 0;
j < 5; j++)
{
if (j == 3)
{continue Heading;}
_______________________________________________
__________________________________________
function
concatenate(fn, ln)
{
var name;
name = fn + ln;
return name;
}
function fullname()
{
var c;
c =
concatenate('Malathi',
'Sivakumar');
document.write
(c );
}
</script>
</head>
<body>
<form>
<input type="button"
onclick="sayHello()"
value="Greetings">
<input type="button"
onclick="fullname()"
value="Click Here">
</form>
</body>
</html>
அதாவெத c = concatenate(‘Malathi’,
‘Sivakumar’) எனக வகாடுப்பதன் மூலம,
அடள்ப்புககுிககுள உளள மைதிப்புகள
concatenate(fn, ln) என்று
வெடளரியறுககப்பகடடுளள function-ககுள உளளீடு
மைதிப்புகளாக் வசன்று அவெற்றுககுள
உளளவெற்டளற் வசியிலபடுததம.
concatenate(fn, ln)-ககுள name எனும ஒரு
variable-வெடளரியறுககப்பகடடு அதிில, fn, ln
வெிழறிய வசலுததப்பகட் 2 தனிததனி மைதிப்புகள
இடளணககப்பகடடு MalathiSivakumar எனும
ஒறர மைதிப்பாக றசமககப்படும. பின்னர் இந்த
மைதிப்பு றசமககப்பகடடுளள name எனும
variable, return keyword மூலம வவெளறிய
அனுப்பப்படுகிறத. இவ்வொறு வவெளறிய
வெந்தளள இந்த மைதிப்றப c எனும variable-ில
றசமககப்பகடடு வவெளப்படுததப்படுகிறத.
Events
ஒரு விிஷியம browser-ில நன்ப்பதற்கு நனாம
வசய்யும ஒவ்வவொன்றும Events எனப்படும.
ஒரு வபாததாடளன வசாடுககுவெத, Mouse-ஐ
நனகர்ததவெத, Page-ஐ load வசய்வெத றபான்ற
ஒவ்வவொன்றும ஒவ்வவொரு Events ஆகும.
றமைற்கண் அறத Program- ஐ நனாம Events-
ககும எடுததகவகாளளலாம. அதிில onclick
என்பத ஒரு event. அடளதறிய onmouseover,
onmouseout எனும events வகாணடு மைாற்ி
இியககிப் பார்ககவும.
<html>
<head>
<script
type="text/javascript">
function sayHello()
{
document.write
("Hello Buddy! Welcome!");
}
function
concatenate(fn, ln)
{
var name;
name = fn + ln;
return name;
}
function fullname()
{
var c;
c =
concatenate('Malathi',
'Sivakumar');
document.write
(c );
}
</script>
</head>
<body>
<form>
<input type="button"
onmouseover="sayHello()"
value="Greetings">
<input type="button"
onmouseout="fullname()"
value="Click Here">
</form>
</body>
</html>
onmouseover=”sayHello()”எனுமறபாத
"Greetings” வபாததானின் அருகிில mouse-ஐ
வகாணடு வசிலலும றபாறத sayHello()
இியககப்பகடடுவிடும.
onmouseout=”fullname()”எனுமறபாத "Click
Here” வபாததானின் அருகிில mouse-ஐ
வகாணடு வசிலலும றபாத எதவும நகழைாத.
ஆனாில அஙகிருந்த mouse-ஐ வவெளறிய
நனகர்ததமறபாத sayHello()
இியககப்பகடடுவிடும.
7 Window-வின் பணபுகள
location
ஒரு வெடளலததளதடளத நனாம பியன்படுததிக
வகாணடருககுமறபாத, திடீவரன்று ‘Home’
எனும வபாததாடளன அுததி, அதன் மதில
பககததிற்கு் வசிலறவொம அிலலவொ, இதற்காக
window.location எனும பணபு பியன்படுகிறத.
அதாவெத browser-ன் எந்தப் பககததிில பியனரர்த
இருந்தாலும, ஒரு வபாததாடளன அுததினாில,
ஒரு குிப்பிகட் url-ககு் வசிலலுமைாறு அடளமைகக
இந்தப் பணபு பியன்படுகிறத.
<html>
<head>
<script
type="text/javascript">
<!--
function
Redirect()
{
window.location="http://www.ka
niyam.com";
}
//-->
</script>
</head>
<body>
<form>
<input type="button"
onclick="Redirect()"
value="Redirect Me">
</form>
</body>
</html>
Dialog Boxes
<html>
<head>
<script
type="text/javascript">
<!--
function box1()
{
alert ("This is
a warning message!");
}
function box2()
{
var x =
confirm("Do you want to
continue ?");
if( x == true )
{document.write ("User wants
to continue!");}
else{document.write ("User
does not want to continue!");}
}
function box3()
{
var x =
prompt("Please enter your name
: ", "your name goes here");
document.write("Hello! Welcome
" + x);
}
//-->
</script>
</head>
<body>
<form>
<input type="button"
onclick="box1()" value="Alert
box">
<input type="button"
onclick="box2()"
value="Confirm box">
<input type="button"
onclick="box3()" value="prompt
box">
</form>
</body>
</html>
User wants to
continue!
prompt():
Prompt() box- ஆனத நனமம்ம ஒரு றகளவிடளிய
எுப்பி, அதற்கான பதிடளல நனமம்மருந்த
வபற்றுகவகாணடு, பின்னர் அதற்றகற்ற
வெடளகயிில வசியிலபடும தன்டளமை வகாண்த.
எனறவெ இத வவெளப்படுததகின்ற வபகடடககுள
ஒரு றகளவியும, ஒரு input box-ம காணப்படும.
றகளவிியாக என்ன வவெளப்ப் றவெணடும,
input box-ில என்ன வதன்ப் றவெணடும
என்படளதவியிலலாம, prompt()-ககுள நனாம
வெடளரியறுதத வி்லாம.
Hello! Welcome Aarthi
Irudhayaraj
9 Exception Handling
<html>
<head>
<script
type="text/javascript">
<!--
function one()
{
var y = 0;
try
{document.write(x);}
catch (e)
{document.write(e+"</br>");}
try
{
if (y==0)
{throw( "Variable should not
hold zero" ); }
}
catch (e)
{document.write(e+"</br>");}
finally
{document.write("Execution
Completed" );}
}
window.onerror =
function (a,b,c)
{
alert(a);
alert(b);
alert(c);
}
//-->
</script>
</head>
<body>
<form>
<input type="button"
onclick="one()"
value="Example1">
<input type="button"
onclick="two()"
value="Example2">
</form>
</body>
</html>
Execution Completed
Error Message:
URL:
Line Number:
10 Form Validations,
Javascript Objects &
Animations
_______________________________________________
__________________________________________
தகவெிலகடளள றசாதிததில
ஒரு விணணப்பப் படவெதடளத நனாம பர்ததி
வசய்தவிகடடு Submit வபாததாடளன
வசாடுககினாில, உலாவிியானத நனாம வகாடுதத
விவெரஙகடளள server-ககு அனுப்புவெதற்கு
மன்னர், எிலலாம சரிியாக உளளதா என்
றசாதிககும. ஏதாவெத விவெரஙகடளள நனாம
வகாடுககத தவெியிருந்தாறலா அிலலத
தவெறுதலாகக வகாடுததிருந்தாறலா,
உலாவிியானத ஒரு popup மூலம அதடளன
நனமைககுத வதரிியப்படுததம. சரிியான
விவெரஙகடளளக வகாடுதத முவெதமைாக
படவெதடளதப் பர்ததி வசய்யுமவெடளர, எந்த ஒரு
விவெரதடளதயும server-ககு அனுப்பாத. இதறவெ
Client side validations எனப்படும. இதடளன
Javascript எவ்வொறு வசய்கிறத என்படளதப்
பின்வெருமைாறு காணலாம.
<html>
<head>
<script
type="text/javascript">
<!--
function
validate()
{
if( document.myForm.Name.value
== "" )
{
document.myForm.Name.focus() ;
return
false;
}
var emailID =
document.myForm.EMail.value;
var reg =
/^([A-Za-z0-9_\-\.])+\@([A-Za-
z0-9_\-\.])+\.([A-Za-z]{2,4})
$/;
if
(reg.test(emailID) == false)
{
document.myForm.EMail.focus()
;
return
false;
}
if( document.myForm.Zip.value
== "" ||
isNaN( document.myForm.Zip.val
ue ) ||
document.myForm.Zip.value.leng
th != 5 )
{
document.myForm.Zip.focus() ;
return
false;
}
if( document.myForm.Country.va
lue == "-1" )
{
return( true );
}
//-->
</script>
</head>
<body>
<form
action="/cgi-bin/test.cgi"
name="myForm"
onsubmit="return(validate());"
>
<table
cellspacing="2"
cellpadding="2" border="1">
<tr>
<td
align="right">Name</td>
<td><input
type="text" name="Name"
/></td>
</tr>
<tr>
<td
align="right">EMail</td>
<td><input
type="text" name="EMail"
/></td>
</tr>
<tr>
<td
align="right">Zip Code</td>
<td><input
type="text" name="Zip" /></td>
</tr>
<tr>
<td
align="right">Country</td>
<td>
<select
name="Country">
<option
value="-1" selected>[choose
yours]</option>
<option
value="1">USA</option>
<option
value="2">UK</option>
<option
value="3">INDIA</option>
</select>
</td>
</tr>
<tr>
<td
align="right"></td>
<td><input
type="submit" value="Submit" /
></td>
</tr>
</table>
</form>
</body>
</html>
view rawValidations.html hosted
with by GitHub
Encapsulation:
இந்த a-வொனத human-ன் அடளனதத விதமைான
வசியிலபாடுகடளளயும, அணுகுகின்ற
அதிகாரதடளதப் வபற்று வசியிலபடுவெறத
‘Encapsulation’ எனப்படும. அதாவெத
எஙவகிலலாம print a எனக வகாடுககிறறாறமைா,
அஙவகிலலாம அதிில றசமககப்பகடடுளள
அடளனதத மைதிப்புகளம வவெளப்படும. இந்த a-
ஆனத Object-ன் மைறுவெடவெமைாக
வசியிலபடுவெதாில, இத ஒரு சாதாரண variable-
ஆக கருதப்ப்ாமைில, Instance என்று
அடளழைககப்படும. Object-ன் ஒரு Instance-ககும,
அதன் Methods & Properties-ககும உளள
உறறவெ "Encapsulation” ஆகும.
Inheritance:
இப்வபாுத kid எனும மைற்வறாரு புதிிய object-
ஐ உருவொககப்றபாகிறறாம. இதற்குள human-ன்
பணபுகள மைற்றும வசியிலபாடுகள்ன் றசர்தத
புதிதாக் சல பணபுகள மைற்றும
வசியிலபாடுகடளளயும றசர்ப்பதற்கு,
Polymorphism:
Print 5+8 எனக வகாடுககுமறபாத, அத 13
எனும மைதிப்பிடளன வவெளப்படுததம. அதறவெ
Print ‘5+8’ என நனாம வகாடுததாில, அத 58
எனும மைதிப்பிடளன வவெளப்படுததம. அதாவெத
Print எனும ஒறர function, வவெவ்றவெறு
விதஙகளில வசியிலபடுததப்படுகின்றன.
இதறவெ Polumorphism-ககு ஓர் சறந்த
உதாரணம ஆகும.
12 Javascript Objects
<html>
<head>
<script
type="text/javascript">
<!--
var records = new
Object();
records.name =
"Nithya";
records.age = 29;
function attn(x,
y){
this.name = x;
this.status =
y;
}
//-->
</script>
</head>
<body>
<script
type="text/javascript">
document.write(records.name +
records.age + "<br>");
document.write(attendance.name
+ attendance.status + "<br>");
</script>
</body>
</html>
<html>
<head>
<script
type="text/javascript">
<!--
function a1()
{
document.write
(Number.MAX_VALUE+'<br/>'+Numb
er.MIN_VALUE+'<br/>'+Number.PO
SITIVE_INFINITY+'<br/
>'+Number.NEGATIVE_INFINITY+'<
br/>'
+Number.NaN+'<br/>'
+Number.prototype+'<br/>'
+Number.constructor);
}
//-->
</script>
</head>
<body>
<form>
<input type="button"
value="Click Me"
onclick="a1();" />
</form>
</body>
</html>
view rawBuilt in
objecets_numbers_properties.ht
ml hosted with by GitHub
<html>
<head>
</head>
<body>
<script
type="text/javascript">
var num=28542;
document.write
(num.toExponential()+'<br/>'+n
um.toExponential(5)+'<br/>'+nu
m.toFixed(2)+'<br/
>'+num.toLocaleString()+'<br/
>'+num.toPrecision(3)+'<br/
>'+num.toString(3)+'<br/
>'+num.valueOf()+'<br/>')
</script>
</body>
</html>
view rawBuilt in
objects_numbers_methods.html hos
ted with by GitHub
இத Number எனும Object-ன் Properties
மைற்றும Methods எப்பட வசியிலபடுகின்றன
என்படளதக காகடடுகிறத. இடளத உஙகளாறலறிய
புரிந்த வகாளள மடயும. இவ்வொறற Boolean,
Strings, Arrays, Date, Math & RegExp
றபான்ற பலவெற்றுககும பிலறவெறு வெடளகியான
Properties மைற்றும Methods உளளன. இவெற்டளற
இடளணியததின் தடளண மூலம வதரிந்த
வகாளளவும.
13 Animation
<html>
<head>
<script
type="text/javascript">
<!--
var imgObj = null;
function init(){
imgObj =
document.getElementById('myIma
ge');
imgObj.style.position=
'relative';
imgObj.style.left = '0px';
}
function
moveinch(){
imgObj.style.left =
parseInt(imgObj.style.left) +
10 + 'px';
}
function
moveRight(){
imgObj.style.left =
parseInt(imgObj.style.left) +
10 + 'px';
animate =
setTimeout(moveRight,20); //
call moveRight in 20msec
}
function stop(){
clearTimeout(animate);
imgObj.style.left = '0px';
}
window.onload
=init;
//-->
</script>
</head>
<body>
<form
action="/cgi-bin/test.cgi"
name="myForm"
onsubmit="return(validate());"
>
<img id="myImage"
src="D:\JavaScript\img1.png" /
>
<p>Click button below
to move the image to right</p>
<input type="button"
value="Move 1 inch"
onclick="moveinch();" />
<input type="button"
value="Move right"
onclick="moveRight();" />
<input type="button"
value="Stop" onclick="stop();"
/>
</form>
</body>
</html>
_______________________________________________
__________________________________________
<html>
<head>
<script
src="https://ajax.googleapis.c
om/ajax/libs/jquery/3.2.1/jque
ry.min.js">
</script>
<script>
jQuery(document).ready(functio
n(){
jQuery("button").click(functio
n(){
var x =
jQuery("p");
x.css("color","blue");
});
});
</script>
</head>
<body>
<p>Getting an
identity is important</p>
<button>Desired
Changes</button>
</body>
</html>
சாதாரண வவெளப்பாடு:
_______________________________________________
__________________________________________
<head>
<style type="text/css">
#p1
{
color: blue;
background-color: pink;
font-weight: bold;
}
</style>
<script
src="https://ajax.googleapis.c
om/ajax/libs/jquery/3.2.1/jque
ry.min.js">
</script>
<script>
$
(document).ready(function(){
$("#1").click(function()
{
alert ($
("#p1").css("background-
color"));
});
$("#2").click(function()
{
$
("#p1").css("font","italic
14pt sans-serif");
});
});
</script>
</head>
<body>
<p id='p1'>Getting an
identity is important</p>
<button
id='1'>Getting value</button>
<button
id='2'>Setting value</button>
</body>
</html>
Jquery elements-ன்
இியககஙகடளளத
றதாற்றுவிககும விதம
<html>
<head>
<script
src="https://ajax.googleapis.c
om/ajax/libs/jquery/3.2.1/jque
ry.min.js">
</script>
<script>
$
(document).ready(function(){
$
("button").click(function(){
$
("#p1").hide(600);
$
("#p3").toggle("slow");
$
("#f1").slideUp("slow");
$
("#dv1").fadeOut("slow");
$
("#dv2").fadeTo(400,0.5);
$
("#dv3").animate({"font-
size" : "24pt"}, "slow");
});
});
</script>
</head>
<body>
<p id='p1'>Getting an
identity is important</p>
<p id='p2'>Doing the
right things at right time</p>
<p id='p3'>Best
things will always comes to
you</p>
<p id="p4">Big data
is the emerging trend</p>
<p id="p5">Data
Science is different from Big
data</p>
<div id="dv1">You can
feel the freedom
everywhere</div>
<div id='dv2'>win-win
situation is not always
possible in family world</div>
<div id="dv3">Come
out of the shell</div>
<form id='f1'
action="">
<input id="r1"
type="radio" name="gender"
value="female"> Female<br>
<input id="r2"
type="radio" name="gender"
value="male"> Male<br>
</form>
<button>Desired
Changes</button>
</body>
</html>
நரலுககான விளககம:
hide() -ஆனத p1-எனும id-ஐக வகாண்
வெரிடளிய மைடளறககிறத. இதற்குள
வகாடுககப்பகட் 600 என்பத மைடளறததில
நனடள்வபறும விததடளத வமைதவொகக காகட்
உதவும.
சாதாரண வவெளப்பாடு:
jQuery ஏற்படுததிிய மைாற்றம:
16 jQuery- வெடளலததளப்
பககஙகளில உளளவெற்டளற
மைாற்றுதில
_______________________________________________
__________________________________________
<html>
<head>
<script
src="https://ajax.googleapis.c
om/ajax/libs/jquery/3.2.1/jque
ry.min.js">
</script>
<script>
$
(document).ready(function(){
$
("#1").click(function(){
$
("#flower").attr("src","two.jp
g");
});
$
("#2").click(function(){
$("#flower").attr(
{"src":"two.jpg","height":"100
","width":"500"} );
});
$
("#3").click(function(){
$
("#flower").removeAttr("width
height");
});
});
</script>
</head>
<body>
<button id='1'>Modify
Image</button>
<button id='2'>Modify
sizing</button>
<button id='3'>Remove
sizing</button>
<img id='flower'
src="one.jpg">
</body>
</html>
view
raw04_1_jquery_modify_images.html hosted
with by GitHub
சாதாரண வவெளப்பாடு:
Modify Image-ஐ வசாடுககினாில ஏற்படும
மைாற்றம:
<html>
<head>
<script
src="https://ajax.googleapis.c
om/ajax/libs/jquery/3.2.1/jque
ry.min.js">
</script>
<script>
$
(document).ready(function(){
$
("#1").click(function(){
alert ( $
("#01").text() );
alert ( $
("#01").html() );
});
$
("#2").click(function(){
$
("#01").text("<b>All the
glitters are not gold </b> -
famous proverb");
});
$
("#3").click(function(){
$
("#01").html("<b>All the
glitters are not gold </b> -
famous proverb");
});
});
</script>
</head>
<body>
<p id='01'> <b>All
the world is a stage </b> -
famous quote</p>
<button
id='1'>Reading content - text
& html</button>
<button id='2'>Modify
content - text()</button>
<button id='3'>Modify
content - html()</button>
</body>
</html>
view raw04_2_jquery_modify_text vs
html.html hosted with by GitHub
சாதாரண வவெளப்பாடு:
<html>
<head>
<script
src="https://ajax.googleapis.c
om/ajax/libs/jquery/3.2.1/jque
ry.min.js">
</script>
<script>
$
(document).ready(function(){
$
("#1").click(function(){
alert ($
("#dv1").offset().left + "," +
$("#dv1").offset().top);
});
$
("#2").click(function(){
$
("#dv1").offset({"left":50,
"top":100});
});
});
</script>
</head>
<body>
<div id="dv1">Come
out of the shell</div>
<button
id='1'>Reading the current
position</button>
<button
id='2'>Modifying the
position</button>
</body>
</html>
view
raw04_3_jquery_modify_positions.html hoste
d with by GitHub
சாதாரண வவெளப்பாடு:
<html>
<head>
<script
src="https://ajax.googleapis.c
om/ajax/libs/jquery/3.2.1/jque
ry.min.js">
</script>
<script>
$
(document).ready(function(){
$
("#1").click(function(){
alert ( $
("#a1").val() );
alert ( $
("#a2").val() );
alert ( $
("[name=gender]:checked").val(
) );
});
$
("#2").click(function(){
$
("#a1").val("India");
$
("#a2").val("Green");
$
("input[name=gender]").val(["m
ale"]);
});
});
</script>
</head>
<body>
<form action="">
<input id="a1"
type="text" name="address"
value="Enter Address..."/>
<select id="a2"
name="color" size="3">
<option>Red</option>
<option>Green</
option>
<option>Blue</option>
</select>
<input id="r1"
type="radio" name="gender"
value="female"> Female
<input id="r2"
type="radio" name="gender"
value="male"> Male
</form>
<button
id='1'>Reading the
values</button>
<button
id='2'>Modifying the
values</button>
</body>
</html>
view
raw04_4_jquery_modify_forms.html hosted
with by GitHub
சாதாரண வவெளப்பாடு:
<head>
<script
src="https://ajax.googleapis.c
om/ajax/libs/jquery/3.2.1/jque
ry.min.js">
</script>
<script>
$
(document).ready(function(){
var a = {
note1 : "Ahhh
gaaga gaagaa",
note2 : "Adi
sakka",
toString :
function ()
{
return
this.note1 + "\n" +
this.note2;
}
};
$
("#p1").data("notes",a);
$
("#p1").click(function(){
var b = $
("#p1").data("notes");
alert ( b );
});
$
("#1").click(function(){
$
("#p1").removeData("notes");
});
});
</script>
</head>
<body>
<p id='p1'>Finally the
girl the one who is doing
everything from the begining</
p>
<button id='1'>Remove
comment</button>
</body>
</html>
view
raw04_5_jquery_modify_comments.html host
ed with by GitHub
சாதாரண வவெளப்பாடு:
<html>
<head>
<script
src="https://ajax.googleapis.c
om/ajax/libs/jquery/3.2.1/jque
ry.min.js">
</script>
<script>
$
(document).ready(function(){
$
("button").click(function(){
$("#p1").before($
("#p2"));
$("<p>All the
<i>leaves</i> are falling
down</p>").insertBefore($
("#p3"));
$
("#p3").clone().attr("id","abc
d_copy").appendTo($("#dv1"));
$("#p4").wrap($
("#p5"));
$
("#dv2").replaceWith($
("#p5"));
$("#f1").remove();
$
( $.parseHTML("<i>All the
leaves</i> are falling
down") ).insertAfter($
("#dv3"));
});
});
</script>
</head>
<body>
<p id='p1'>Getting an
identity is important</p>
<p id='p2'>Doing the
right things at right time</p>
<p id='p3'>Best
things will always comes to
you</p>
<p id="p4">Big data
is the emerging trend</p>
<p id="p5">Data
Science is different from Big
data</p>
<div id="dv1">You can
feel the freedom
everywhere</div>
<div id='dv2'>win-win
situation is not always
possible in family world</div>
<div id="dv3">Come
out of the shell</div>
<form id='f1'
action="">
<input id="r1"
type="radio" name="gender"
value="female"> Female<br>
<input id="r2"
type="radio" name="gender"
value="male"> Male<br>
</form>
<button>Desired
Changes</button>
</body>
</html>
view
raw04_6_jquery_modify_webcontent.html hos
ted with by GitHub
நரலுககான விளககம:
before() -ஆனத p2-எனும id-ஐக வகாண்
வெரிடளிய p1-ககு மன்னாில அடளமைககிறத.
•jQuery Object-ஆக
வெடளரியறுககப்பகடடுளளவெற்றுககுள க்ந்த
வசிலலில
•jQuery Object-ஆக
வெடளரியறுககப்பகடடுளளவெற்ின்
உகடவசய்திகளாக இருப்பவெற்றுககுள க்ந்த
வசிலலில
இந்த இரணடற்கும each() எனும method
பியன்படுகிறத.
jQuery Object-ஆக
வெடளரியறுககப்பகடடுளளவெற்றுககுள க்ந்த
வசிலலில:
$("p”).each (function
(index,element)
{if ($(element).css ("color”)
=== "rgb(0, 191, 255)”)
{$(element).css
("color”,”rgb(255, 0, 0)”);}
});
<html>
<head>
<script
src="https://ajax.googleapis.c
om/ajax/libs/jquery/3.2.1/jque
ry.min.js">
</script>
<script>
$
(document).ready(function(){
$
("button").click(function(){
$
("#beverages").attr
("type","circle");
$
("#beverages").children().each
( function(i,x) {$
(x).text((i+1)+"."+$
(x).text());} );
$("li:first-
child").css ("background-
color","skyblue");
$("li:first-
child").next().css
("color","red");
$("li:first-
child").siblings().css
("background-
color","lightgreen");
$("p").each
(function (index,element)
{if ($
(element).css ("color") ===
"rgb(0, 191, 255)")
{$
(element).css
("color","rgb(255, 0, 0)");}
});
});
});
</script>
</head>
<body>
<ul id='beverages'>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<p style="color:rgb(0,
191, 255)">Doing the right
things at right time</p>
<p>Best things will
always comes to you</p>
<button>Desired
Changes</button>
</body>
</html>
http://freetamilebooks.com/authors/
nithyaduraisamy/
கணிியம அறகககட்டளள
மகக நனன்ி !
Kaniyam Foundation
Account Number : 606101010050279
Union Bank Of India
West Tambaram, Chennai
IFSC - UBIN0560618