Presentation is loading. Please wait.

Presentation is loading. Please wait.

ALBERT WAVERING BOBBY SENG. Week 5: More JavaScript  Quiz  Announcements/questions.

Similar presentations


Presentation on theme: "ALBERT WAVERING BOBBY SENG. Week 5: More JavaScript  Quiz  Announcements/questions."— Presentation transcript:

1 ALBERT WAVERING BOBBY SENG

2 Week 5: More JavaScript  Quiz  Announcements/questions

3 Built-in JS Objects  Boolean (true or false)  String  Array  Math  Date  Regular Expression

4 Boolean  var iWin = new Boolean(); = new Boolean(1); = new Boolean (0); = new Boolean(true); = new Boolean(false);

5 Boolean Values  True  1 (or any nonzero number)  true  "anything goes here"  False  0  false  ""

6 String  Built-in functions:  String.lengthevaluates to length of string  String.toUpperCaseall characters to upper case  String.toLowerCaseall characters to lower case  String.charAtreturns character at index  String.concatcombines two strings (like +)  String.splitarray elements divided on a match  String.substring returns a subset of characters  String.match replace, search: Reg Exp functions

7 String var myPhrase = "Four score and seven years ago"; myPhrase.charAt(3); myPhrase.substr(5,9); myPhrase.split(" "); myPhrase.toUpperCase();

8 String myPhrase.charAt(3)'r' myPhrase.substr(5,9);'score' myPhrase.toUpperCase();"FOUR SCORE AND SEVEN YEARS AGO" var myArray = myPhrase.split(" "); myArray = ["Four","score","and","seven","years", "ago"] (this is an array of size 6)

9 Array  var myArray = new Array();  myArray[0] = 5; my2DArray[1][2] = 8;  document.write(myArray[1])  Built-in functions:  concatcombine two or more arrays  popremoves last element  pushadds element to end of array  shiftremoves first element of array  unshiftadds element to beginning of array  reversereverses order of elements

10 Math  Constants  Math.E  Math.PI  others  Methods  Math.round  Math.random  Math.floor  Math.ceil  Math.cos, sin, tan  Math.sqrt  Math.pow

11 Date  var myDate = new Date(); //current date, time  Date(ms) = milliseconds since 1/1/1970  Date(dateString) = interprets dateString  Date(y, m, d, h, m, s, ms) = input specific numerals  Comparation  Less than, greater than (after, before)  Methods  getFullYear, getMonth, getDay, getDate  getHours, getMinutes, getSeconds, getMilliseconds, getTime

12 Regular Expressions  Used to evaluate regular languages  Create patterns to match specific occurrences in strings  Can use to replace, separate, and locate text  var myRegEx = /pattern/modifiers  Example  var myRegEx = /[A-Za-z0-9]/g  Look online for specific pattern and modifier syntax (won’t quiz you on this)

13 So how is this useful?!  Form Submission  Dynamic Content  Functionality  Web Applications

14 JS: Making Things Happen  We want to interact with HTML of page  Specifically, elements  To do any sort of action (read, change, etc) an element or group of elements, we need to select it/them  Selection tools  document.myFormName.elementName  document.getElementByID("myElementID")  DON’T USE THESE

15 JS: Selecting Elements  First brick wall with interoperability  Element selection is not universal across IE 6-9, Firefox, Chrome, and Safari  Handle each case?  Heck no  jQuery  JavaScript ‘library’  Suite of tools that are very useful for JS developers

16 jQuery  http://jquery.com/ http://jquery.com/  Element selection  User interface elements  Event handling  Animation  AJAX data transfer

17 jQuery  Currently 24kb  http://code.jquery.com/jquery-1.4.2.min.js http://code.jquery.com/jquery-1.4.2.min.js  Include this library if you’re using jQuery, but reference it from your own server  http://docs.jquery.com/Main_Page http://docs.jquery.com/Main_Page  jQuery operations make use of the $ variable

18 Back to Reality  Element selection in jQuery  $("*")selects all elements  $("#myID")selects element with ID myID  $(".myClass")selects elements of class myClass  $("anElement") selects elmnts of type anElement  Many more, check documentation for examples $(“#albert”).attr()

19 jQuery: Attributes .addClass .attr .hasClass .html .removeClass .val

20 jQuery: Traversing .children .each .next .parent .siblings

21 jQuery: Manipulation .append .height .position .remove .replaceWith .text

22 jQuery: CSS  All similar functions we already covered

23 jQuery: Events .bind,.unbind .click .dblclick .focusin,.focusout .keydown,.keyup,.keypress .mouseenter,.mousemove,.mouseleave,.mouseout,.mouseover .ready .select .scroll .toggle

24 jQuery: Effects .animate .delay .fadeIn,.fadeOut .hide,.show .slideDown,.slideUp .stop .toggle

25 jQuery: AJAX .ajaxSend,.ajaxError,.ajaxComplete .ajaxStart,.ajaxStop,.ajaxSuccess  jQuery.get, jQuery.getJSON, jQuery.getScript .load .post .serialize

26 Homework  Create a webpage composed of the following: one HTML page that includes a form with text areas, a checkbox, and a button. In a linked.js file, use jQuery to make the entered information appear elsewhere on the page. For examples, check the jQuery documentation. jQuery documentation.  You will need to link the jQuery library before any jQuery commands you try to run:  Download a copy of jQuery from www.jquery.com. Your homework must pass W3C validation. Don't worry about emailing a copy of jQuery with your homework - we've got our own copy ;)www.jquery.com


Download ppt "ALBERT WAVERING BOBBY SENG. Week 5: More JavaScript  Quiz  Announcements/questions."

Similar presentations


Ads by Google