Вы находитесь на странице: 1из 19

JAVASCRIPT

What is JavaScript ?

JavaScript was first known as LiveScript


Advantages of JavaScript
• Less server interaction
• Immediate feedback to the visitors
• Increased interactivity
• Richer interfaces
Limitations of JavaScript
• Client-side JavaScript does not allow the reading or writing of
files. This has been kept for security reason.
• JavaScript cannot be used for networking applications
because there is no such support available.
• JavaScript doesn't have any multi-threading or multiprocessor
capabilities.
JavaScript Development Tools
• Microsoft FrontPage
• Macromedia Dreamweaver MX
• Macromedia HomeSite 5
Why do we Study JavaScript?
JavaScript is one of the 3 languages all web
developers must learn:

• HTML to define the content of web pages


• CSS to specify the layout of web pages
• JavaScript to program the behavior of web
pages
JavaScript was invented by Brendan Eich in 1995
JavaScript Can Change HTML Content
One of many JavaScript HTML methods is getElementById().
This example uses the method to "find" an HTML element (with id="demo")
and changes the element content (innerHTML) to "Hello JavaScript":

<!DOCTYPE html>
<html>
<body>

<h2>What Can JavaScript Do?</h2>

<p id="demo">JavaScript can change HTML content.</p>

<button type="button" onclick='document.getElementById("demo").innerHTML = "Hello Ja

</body>
</html>
<!DOCTYPE html>
<html>
<body>

<h2>What Can JavaScript Do?</h2>

<p id="demo">JavaScript can change HTML content.</p>

<button type="button" onclick='document.getElementById("demo").innerHTML =


"Hello JavaScript!"'>Click Me!</button>

</body>
</html>
   
JavaScript Can Change HTML Attribute Values
In this example JavaScript changes the value of the src (source) attribute of an <img> tag:

Turn on the light Turn off the light


<!DOCTYPE html>
<html>
<body>

<h2>What Can JavaScript Do?</h2>

<p>JavaScript can change HTML attribute values.</p>

<p>In this case JavaScript changes the value of the src (source) attribute of an image.</p>

<button onclick="document.getElementById('myImage').src='pic_bulbon.gif'">
Turn on the light</button>

<img id="myImage" src="pic_bulboff.gif" style="width:100px">

<button onclick="document.getElementById('myImage').src='pic_bulboff.gif'">
Turn off the light</button>

</body>
</html>
JavaScript Where To
The <script> Tag

<script>
Javascript code……
</script>
JavaScript Functions and Events

function clickMe() {
javascript code…….
}
JavaScript in <head> or <body>
JavaScript in <head>
JavaScript in <body>
External JavaScript

External JavaScript Advantages


Placing scripts in external files has some advantages:
• It separates HTML and code
• It makes HTML and JavaScript easier to read and maintain
• Cached JavaScript files can speed up page loads

<script src=“myScript.js”></script>
JavaScript Variables

var ------ variable


<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Variables</h2>

<p>In this example, x is defined as a variable.


Then, x is assigned the value of 6:</p>

<p id="demo"></p>

<script>
var x;
x = 6;
document.getElementById("demo").innerHTML = x;
</script>

</body>
</html>

Вам также может понравиться