1 / 14

JavaScript.3

JavaScript.3. 2012. Встроенные объекты. String Math Date. String. Var myString=“hello” Var myString=new String (“hello”). Конкатенация. document.write(“ of <B>” + navigator.appName + “</B>.”) var msg = “Four score” msg = msg + “ and seven” msg = msg + “ years ago,”

jsegura
Download Presentation

JavaScript.3

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. JavaScript.3 2012

  2. Встроенные объекты • String • Math • Date

  3. String • Var myString=“hello” • Var myString=new String (“hello”)

  4. Конкатенация • document.write(“ of <B>” + navigator.appName + “</B>.”) • var msg = “Four score” • msg = msg + “ and seven” • msg = msg + “ years ago,” • var msg = “Four score” • msg += “ and seven” + “ years ago”

  5. Методы объекта String • var result = string.toUpperCase() • var result = string.toLowerCase() • var foundMatch = false • if (stringA.toUpperCase() == stringB.toUpperCase()) { • foundMatch = true • }

  6. Поиск подстроки • var isWindows = false • if (navigator.userAgent.indexOf(“Win”) != -1) { • isWindows = true • }

  7. Копирование символов и подстрок • var stringA = “Building C” • var bldgLetter = stringA.charAt(9) • // result: bldgLetter = “C” • var stringA = “banana daiquiri” • var excerpt = stringA.substring(2,6) • // result: excerpt = “nana”

  8. Работа со строками • var stringA = “The United States of America” • var excerpt = stringA.substring(stringA.indexOf(“ “) + 1, stringA.length) • // result: excerpt = “United States of America”

  9. The Math Object • var piValue = Math.PI • var rootOfTwo = Math.SQRT2 • var larger = Math.max(value1, value2) • var result = Math.round(value1) • Math.floor(Math.random() * (n + 1)) • newDieValue = Math.floor(Math.random() * 6) + 1

  10. The Date Object • var today = new Date() • var someDate = new Date(“Month dd, yyyy hh:mm:ss”) • var someDate = new Date(“Month dd, yyyy”) • var someDate = new Date(yy,mm,dd,hh,mm,ss) • var someDate = new Date(yy,mm,dd) • var someDate = new Date(GMT milliseconds from 1/1/1970)

  11. Методы объекта Дата (1) • dateObj.getTime() 0-... Milliseconds since 1/1/70 00:00:00 GMT • dateObj.getYear() 70-... Specified year minus 1900; four-digit year • for 2000+ • dateObj.getFullYear() 1970-... Four-digit year (Y2K-compliant); version • dateObj.getMonth() 0-11 Month within the year (January = 0) • dateObj.getDate() 1-31 Date within the month • dateObj.getDay() 0-6 Day of week (Sunday = 0) • dateObj.getHours() 0-23 Hour of the day in 24-hour time • dateObj.getMinutes() 0-59 Minute of the specified hour • dateObj.getSeconds() 0-59 Second within the specified minute

  12. Методы объекта Дата (2) • dateObj.setTime(val) 0-... Milliseconds since 1/1/70 00:00:00 GMT • dateObj.setYear(val) 70-... Specified year minus 1900; four-digit year • for 2000+ • dateObj.setMonth(val) 0-11 Month within the year (January = 0) • dateObj.setDate(val) 1-31 Date within the month • dateObj.setDay(val) 0-6 Day of week (Sunday = 0) • dateObj.setHours(val) 0-23 Hour of the day in 24-hour time • dateObj.setMinutes(val) 0-59 Minute of the specified hour • dateObj.setSeconds(val) 0-59 Second within the specified minute

  13. Вычисление даты • <HTML><HEAD><TITLE>Date Calculation</TITLE><SCRIPT LANGUAGE=”JavaScript”> • function nextWeek() { • var todayInMS = today.getTime() • var nextWeekInMS = todayInMS + (60 * 60 * 24 * 7 * 1000) • return new Date(nextWeekInMS) • } • </SCRIPT></HEAD><BODY> • Today is: • <SCRIPT LANGUAGE=”JavaScript”> • var today = new Date() • document.write(today) • </SCRIPT> • <BR> • Next week will be: • <SCRIPT LANGUAGE=”JavaScript”> • document.write(nextWeek()) • </SCRIPT></BODY></HTML>

  14. Упражнения • Создайте страницу, в которой имеется поле для ввода электронного адреса и кнопка Submit. Напишите сценарий, который проверяет, верен ли адрес перед отправкой содержимого полей формы. • Посчитайте, сколько дней, часов, минут и секунд вы живете на свете? • Посчитайте с учетом високосных годов. • Напишите сценарий, который при нажатии на кнопку в двух текстовых полях выводит случайные целые числа от 4 до 17, а в третьем поле выводит произведение этих чисел.

More Related