Skip to content

Instantly share code, notes, and snippets.

View h4's full-sized avatar
💭
I may be slow to respond.

Mikhail Baranov h4

💭
I may be slow to respond.
View GitHub Profile
@h4
h4 / string.js
Created March 27, 2012 13:34
JS. Объект String
// 1. Методы объекта String
var str="Hello world!";
document.write(str.length);
document.write("<p>Bold: " + str.bold() + "</p>");
document.write("<p>Italic: " + str.italics() + "</p>");
document.write(str.match("world") + "<br />");
document.write(str.match("World") + "<br />");
document.write(str.indexOf("Hello") + "<br />");
@h4
h4 / regexp.js
Created March 27, 2012 13:38
JS. Регярки
// 1. Поиск подстроки
var birthDate = /(\d+)\.(\d+)\.(\d+)/.exec("Я родился 21.05.1958");
document.write("Дата рождения: ", birthDate[0], " ");
document.write("День рождения: ", birthDate[1], " ");
document.write("Месяц рождения: ", birthDate[2], " ");
document.write("Год рождения: ", birthDate[3], " ");
// 2. Модификаторы
@h4
h4 / taxi.v1.js
Created March 29, 2012 10:49
JS. Задание Taxi
function getTaxiFare(len, hour) {
var price = 200,
nightTax = 0.3;
if (len < 10) {
len = 10;
}
if (hour < 1 || hour > 24) {
return alert('В сутках только 24 часа!');
}
total = len * price;
@h4
h4 / 01.arguments.js
Created March 29, 2012 14:46
JS. Объект Fuction
function initArray() {
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++)
this[i] = initArray.arguments[i];
}
var myFriends = new initArray("Михаил", "Максим", "Сергей", "Леонид");
alert(myFriends.length);
alert(myFriends[0]);
@h4
h4 / 01.attribute.html
Created April 2, 2012 19:43
События в JavaScript
<script type=”text/javascript”>
function yourMessage(){
alert("Функция");
}
</script>
</head>
<body onload="yourMessage()">
</body>
@h4
h4 / exceptions.html
Created April 2, 2012 19:47
Обработка исключений
<html>
<head>
<script type="text/javascript">
var txt="";
function message() {
try {
adddlert("Welcome guest!");
}
catch(err) {
txt="Ошибка на странице.\n\n";
@h4
h4 / 01.open.js
Created April 2, 2012 19:52
Объект window
function openWin() {
myWindow = window.open("", "", "width=200,height=100");
myWindow.document.write("Вот оно - 'myWindow'!");
myWindow.focus();
myWindow.opener.document.write("Это окно, из которого открыли новое окно");
}
@h4
h4 / 01.document_write.js
Created April 2, 2012 20:06
Объект document
for (i=1; i<=6; i++) {
document.write('<h'+i+'>Заголовок '+i.toString().italics()+' уровня</h'+i+'>');
}
@h4
h4 / 01.reload.html
Created April 2, 2012 20:20
Объект window.location
<html>
<head>
<title>Перезагрузка страницы</title>
<script type="text/javascript">
function reloadPage() {
window.location.reload();
}
</script>
</head>
<body>
@h4
h4 / 01.history.html
Created April 2, 2012 20:27
Объекты history, screen и navigator
<form>
<input type=button value="Назад" onclick="history.back()">
</form>