1 / 23

آموزش طراحی وب سایت جلسه یازدهم – جاوا اسکریپت 2

آموزش طراحی وب سایت جلسه یازدهم – جاوا اسکریپت 2. تدریس طراحی وب برای اطلاعات بیشتر تماس بگیرید تاو شماره تماس: 09125773990 09371410986 پست الکترونیک : TargetLearning@gmail.com. Web Design Training Java Scripts #2. Part 11 Author :Babak Tavatav. JavaScript For Loop.

zelda
Download Presentation

آموزش طراحی وب سایت جلسه یازدهم – جاوا اسکریپت 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. آموزش طراحی وب سایتجلسه یازدهم – جاوا اسکریپت 2 تدریس طراحی وببرای اطلاعات بیشتر تماس بگیرید تاوشماره تماس: 0912577399009371410986پست الکترونیک : TargetLearning@gmail.com

  2. Web Design TrainingJava Scripts#2 Part 11 Author :Babak Tavatav

  3. JavaScript For Loop for (var=startvalue;var<=endvalue;var=var+increment){code to be executed}

  4. <html> <body> <script type="text/javascript"> for (i = 0; i <= 5; i++) { document.write("The number is " + i); document.write("<br />"); } </script> <p>Explanation:</p> <p>This for loop starts with i=0.</p> <p>As long as <b>i</b> is less than, or equal to 5, the loop will continue to run.</p> <p><b>i</b> will increase by 1 each time the loop runs.</p> </body> </html>

  5. The while Loop The while loop loops through a block of code while a specified condition is true. Syntax: while (var<=endvalue)  {  code to be executed  } Note: The <= could be any comparing operator.

  6. <html> <body> <script type="text/javascript"> i=0; while (i<=5) { document.write("The number is " + i); document.write("<br />"); i++; } </script> <p>Explanation:</p> <p><b>i</b> is equal to 0.</p> <p>While <b>i</b> is less than , or equal to, 5, the loop will continue to run.</p> <p><b>i</b> will increase by 1 each time the loop runs.</p> </body> </html>

  7. The do...while Loop The do...while loop is a variant of the while loop. This loop will execute the block of code ONCE, and then it will repeat the loop as long as the specified condition is true. Syntax do  {  code to be executed}while (var<=endvalue);

  8. <html> <body> <script type="text/javascript"> i = 0; do { document.write("The number is " + i); document.write("<br />"); i++; } while (i <= 5) </script> <p>Explanation:</p> <p><b>i</b> equal to 0.</p> <p>The loop will run</p> <p><b>i</b> will increase by 1 each time the loop runs.</p> <p>While <b>i</b> is less than , or equal to, 5, the loop will continue to run.</p> </body> </html>

  9. JavaScript Break and Continue Statements

  10. <html> <body> <script type="text/javascript"> vari=0; for (i=0;i<=10;i++) { if (i==3) { break; } document.write("The number is " + i); document.write("<br />"); } </script> <p>Explanation: The loop will break when i=3.</p> </body> </html>

  11. The continue Statement The continue statement will break the current loop and continue with the next value.

  12. <html> <body> <script type="text/javascript"> vari=0; for (i=0;i<=10;i++) { if (i==3) { continue; } document.write("The number is " + i); document.write("<br />"); } </script> <p>Explanation: The loop will break the current loop and continue with the next value when i=3.</p> </body> </html>

  13. exercise • JavaScript For...In Statement

  14. Events By using JavaScript, we have the ability to create dynamic web pages. Events are actions that can be detected by JavaScript. Every element on a web page has certain events which can trigger a JavaScript. For example, we can use the onClick event of a button element to indicate that a function will run when a user clicks on the button. We define the events in the HTML tags. Examples of events: • A mouse click • A web page or an image loading • Mousing over a hot spot on the web page • Selecting an input field in an HTML form • Submitting an HTML form • A keystroke

  15. The try...catch Statement The try...catch statement allows you to test a block of code for errors. The try block contains the code to be run, and the catch block contains the code to be executed if an error occurs. Syntax try  {  //Run some code here  }catch(err)  {  //Handle errors here  }

  16. <html> <head> <script type="text/javascript"> var txt=""; function message() { try { adddlert("Welcome guest!"); } catch(err) { txt="There was an error on this page.\n\n"; txt+="Error description: " + err.description + "\n\n"; txt+="Click OK to continue.\n\n"; alert(txt); } } </script> </head> <body> <input type="button" value="View message" onclick="message()" /> </body> </html>

  17. <html><head><script type="text/javascript">var txt="";function message(){try  {  adddlert("Welcome guest!");  }catch(err)  {  txt="There was an error on this page.\n\n";  txt+="Click OK to continue viewing this page,\n";  txt+="or Cancel to return to the home page.\n\n";  if(!confirm(txt))    {    document.location.href="http://www.sabadekala.com/";    }  }}</script></head><body><input type="button" value="View message" onclick="message()" /></body></html>

  18. JavaScript Special Characters

  19. JavaScript Objects

  20. Object Oriented Programming • Properties • Methods

  21. <script type="text/javascript">var txt="Hello World!";document.write(txt.length);</script>

  22. <script type="text/javascript">var str="Hello world!";document.write(str.toUpperCase());</script>

  23. The END

More Related