Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript.3 2012. Встроенные объекты String Math Date.

Similar presentations


Presentation on theme: "JavaScript.3 2012. Встроенные объекты String Math Date."— Presentation transcript:

1 JavaScript.3 2012

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

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

4 Конкатенация document.write(“ of ” + navigator.appName + “.”) 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 Вычисление даты Date Calculation function nextWeek() { var todayInMS = today.getTime() var nextWeekInMS = todayInMS + (60 * 60 * 24 * 7 * 1000) return new Date(nextWeekInMS) } Today is: var today = new Date() document.write(today) Next week will be: document.write(nextWeek())

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


Download ppt "JavaScript.3 2012. Встроенные объекты String Math Date."

Similar presentations


Ads by Google