1 / 26

CPSP 229D: Web design

ALBERT WAVERING BOBBY SENG. CPSP 229D: Web design. Week 5: More JavaScript. Quiz Announcements/questions. Built-in JS Objects. Boolean (true or false) String Array Math Date Regular Expression. Boolean. var iWin = new Boolean(); = new Boolean(1); = new Boolean (0);

paprika
Télécharger la présentation

CPSP 229D: Web design

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. ALBERT WAVERING BOBBY SENG CPSP 229D: Web design

  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.length evaluates to length of string • String.toUpperCase all characters to upper case • String.toLowerCase all characters to lower case • String.charAt returns character at index • String.concat combines two strings (like +) • String.split array 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" varmyArray = myPhrase.split(" "); myArray = ["Four","score","and","seven","years", "ago"] (this is an array of size 6)

  9. Array • varmyArray = new Array(); • myArray[0] = 5;my2DArray[1][2] = 8; • document.write(myArray[1]) • Built-in functions: • concat combine two or more arrays • pop removes last element • push adds element to end of array • shift removes first element of array • unshift adds element to beginning of array • reverse reverses 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 • varmyDate = 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 • varmyRegEx = /pattern/modifiers • Example • varmyRegEx = /[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/ • 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 • Include this library if you’re using jQuery, but reference it from your own server • 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. • You will need to link the jQuery library before any jQuery commands you try to run: <script type="text/javascript" src="jquery-1.4.2.min.js"></script> • 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 ;)

More Related