Professional Documents
Culture Documents
JavaScript Dokument
JavaScript Dokument
<!DOCTYPE html>
<html lang="pl-PL">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Wewnętrzny kod JavaScript</title>
<script>
var a = prompt("Podaj liczbę a: ");
alert(a);
</script>
</head>
<body>
</body>
</html>
if(question==1) {
alert("Jesteś obywatelem RP. ");
} else {
alert("Nie jesteś obywatelem RP. ");
}
if(wiek>=18) {
odp = "Jesteś pełnoletni.";
} else {
odp = "Nie jesteś pełnoletni.";
}
document.getElementById(‘out’).innerHTML = odp;
}
JS:
function wyswietl(id) {
var plec = document.getElementById(id).value;
document.getElementById(‘out’).innerHTML = plec;
}
JS:
function skrypt() {
var opcja = document.getElementById(‘lista’).value;
alert(opcja);
}
JS:
function tx() {
var a = document.getElementById(‘txta’).value;
document.getElementById("out").innerHTML = a;
}
HTML: <ul>
<li class="item" onClick="komunikat(0)">uczen1</li>
<li class="item" onClick="komunikat(1)">uczen2</li>
<li class="item" onClick="komunikat(2)">uczen3</li>
<li class="item" onClick="komunikat(3)">uczen4</li>
<li class="item" onClick="komunikat(4)">uczen5</li>
</ul>
JavaScript
JS:
function komunikat(index) {
var element = document.getElementsByClassName(‘item’)
[index].innerHTML;
alert(element);
}
JS:
function funkcja() {
var zmienna = document.getElementsByTagName(‘p’)
[0].innerHTML;
alert(zmienna);
}
JS:
function zmiana(id, zrodlo) {
var obiekt = document.getElementById(id);
obiekt.src = zrodlo;
document.querySelector(‘#out’).outerHTML = "<marquee
id=’out’>" + obiekt.src + "</marquee>";
}
function atrybuty(id) {
console.log(document.getElementById(id).src);
console.log(document.getElementById(id).alt);
console.log(document.getElementById(id).title);
console.log(document.getElementById(id).id);
}
JavaScript
4. Ingerowanie w dokument HTML za pomocą kodu JavaScript.
Zmiana koloru tekstu:
<p id="tekst">przykładowy tekst</p> (HTML)
document.getElementById(‘tekst’).style.color = "red";
lub document.getElementById(‘tekst’).style = "color: red;";
5. Szybka powtórka.
document.getElementById(‘id’).value – odnoszenie się do wartości
elementu o podanym id;
document.getElementById(‘id’).checked – odnoszenie się do stanu pola
typu checkbox, które posiada podane id;
document.getElementById(‘id’).innerHTML – odnoszenie się do zawartości
elementu o podanym id;
document.getElementById(‘id’).outerHTML – odnoszenie się do fragmentu
kodu HTML opisującego element o podanym id wraz z jego potomkami;
document.getElementById(‘id’).style – odnoszenie się do stylu CSS
elementu o podanym id;
JavaScript
document.getElementById(‘id’).style.color – odnoszenie się do koloru
elementu o podanym id;
document.getElementById(‘zdj’).src –odnoszenie się do źródła elementu o
podanym id;