Java Script Java Scripts script script tags body

  • Slides: 15
Download presentation

Java. Script • Το Java. Scripts εισάγεται ανάμεσα στα <script> </script> tagsκαι μπορεί να

Java. Script • Το Java. Scripts εισάγεται ανάμεσα στα <script> </script> tagsκαι μπορεί να μπει είτε στο <body> είτε στο <head> της HTML. • Για να χρησιμοποιήσουμε ένα HTML element με την Java. Script, θα χρησιμοποιούμε την document. get. Element. By. Id(id) method. Όπου "id" είναι το attribute που υπάρχει σε όλα τα element του HTML. • H javascript είναι case sensitive <html> <body> <h 1>My Test in ID with javascript</h 1> <p id="my. ID">Test ID</p> <script> elem = document. get. Element. By. Id("my. ID"); elem. inner. HTML = "This is a test in javascript ID"; </script> </body> </html> Παραδείγματα w 3 schools. com

Java. Script <html> <body> <p id="p 1">Hello World!</p> <p id="p 2">Hello World!</p> <script> document.

Java. Script <html> <body> <p id="p 1">Hello World!</p> <p id="p 2">Hello World!</p> <script> document. get. Element. By. Id("p 2"). style. color="blue"; document. get. Element. By. Id("p 2"). style. font. Family="A rial"; document. get. Element. By. Id("p 2"). style. font. Size="larg er"; </script> <p>The paragraph above was changed by a script. </p> </body> </html> Παραδείγματα w 3 schools. com

<html> <body> <h 1>My Web Page</h 1> <p id="my. Par">I am a paragraph. </p>

<html> <body> <h 1>My Web Page</h 1> <p id="my. Par">I am a paragraph. </p> <div id="my. Div">I am a div. </div> <p> <button type="button" onclick="my. Function()">Try it</button> </p> <script> function my. Function() { document. get. Element. By. Id("my. Par"). inner. HTML="Hello Dolly"; document. get. Element. By. Id("my. Div"). inner. HTML="How are you? "; } </script> <p>When you click on "Try it", the two elements will change. </p> </body> </html> ΛΑΘΟΣ <html> <body> <h 1>My Web Page</h 1> <p id="demo">A Paragraph. </p> <div id="my. DIV">A DIV. </div> <script> // Ο Λάθος τρόπος document. get. Element. By. Id("demo"). inner. HTML="Hello Dolly"; document. get. Element. By. Id("my. DIV"). inner. HTML="How are you? "; /* με τον κώδικα αυτόν Μπορούμε να γράψουμε στην ιστοσελίδα Αλλά με τρόπο όχι κομψό */ </script> </body> </html> Παραδείγματα w 3 schools. com

Java. Script Examples <script> function my. Function() { var str="Hello World!"; var n=str. length;

Java. Script Examples <script> function my. Function() { var str="Hello World!"; var n=str. length; document. get. Element. By. Id("demo"). inner. HTM L=n; } </script> String <script> var d=new Date(); document. write(d); Date </script> Παραδείγματα w 3 schools. com

Java. Script Examples <script> var i; var mycars = new Array(); mycars[0] = "Saab";

Java. Script Examples <script> var i; var mycars = new Array(); mycars[0] = "Saab"; mycars[1] = "Volvo"; mycars[2] = "BMW"; Arrays for (i=0; i<mycars. length; i++) { document. write(mycars[i] + " "); } </script> Παραδείγματα w 3 schools. com

Java. Script Examples <script> var fruits = ["Banana", "Orange", "Apple", "Mango"]; function my. Function()

Java. Script Examples <script> var fruits = ["Banana", "Orange", "Apple", "Mango"]; function my. Function() { fruits. pop(); var x=document. get. Element. By. Id("demo"); x. inner. HTML=fruits; } </script> <script> function my. Function() { var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits. splice(2, 0, "Lemon", "Kiwi"); var x=document. get. Element. By. Id("demo"); x. inner. HTML=fruits; } </script> Παραδείγματα w 3 schools. com

Java. Script Examples <button onclick="my. Function('Harry Potter', 'Wizard')">Try it</button> <script> function my. Function(name, job)

Java. Script Examples <button onclick="my. Function('Harry Potter', 'Wizard')">Try it</button> <script> function my. Function(name, job) { alert("Welcome " + name + ", the " + job); } </script> Call a function with arguments Παραδείγματα w 3 schools. com

Java. Script Examples <script> function write. Text(txt) { document. get. Element. By. Id("desc"). inner.

Java. Script Examples <script> function write. Text(txt) { document. get. Element. By. Id("desc"). inner. HTML =txt; } </script> </head> <body> <img src ="planets. gif" width ="145" height ="126" alt="Planets" usemap="#planetmap" /> <map name="planetmap"> <area shape ="rect" coords ="0, 0, 82, 126" onmouseover="write. Text('The Sun and the gas giant planets like Jupiter are by far the largest objects in our Solar System. ')" href ="sun. htm" target ="_blank" alt="Sun" /> </body> </HTML> On mouse over event Παραδείγματα w 3 schools. com

Java. Script Examples <button onclick="my. Function()">Try it</button> <script> function my. Function() { document. get.

Java. Script Examples <button onclick="my. Function()">Try it</button> <script> function my. Function() { document. get. Element. By. Id("demo"). inner. HTM L=Math. round(2. 5); } </script> Document object Παραδείγματα w 3 schools. com

Java. Script Examples Document object <script> document. write("<h 1>Hello World!</h 1>"); </script> <button onclick="my.

Java. Script Examples Document object <script> document. write("<h 1>Hello World!</h 1>"); </script> <button onclick="my. Function()">Try it</button> <script> function my. Function() { var x = document. get. Element. By. Id("demo"); x. inner. HTML=document. domain; } </script> Παραδείγματα w 3 schools. com

Java. Script Examples button onclick="my. Function()">Try it</button> <script> function my. Function() { alert("I am

Java. Script Examples button onclick="my. Function()">Try it</button> <script> function my. Function() { alert("I am an alert box!"); } </script> Παραδείγματα w 3 schools. com

Διάβασμα http: //www. w 3 schools. com/js/default. asp Java. Script Basic Examples Java. Script

Διάβασμα http: //www. w 3 schools. com/js/default. asp Java. Script Basic Examples Java. Script Objects Examples Java. Script HTML DOM Examples Java. Script Browser Objects Examples