This commit is contained in:
szabomarton 2024-10-21 13:16:08 +02:00
parent 9b693c4cf1
commit 7f2ddb3a86
7 changed files with 168 additions and 0 deletions

Binary file not shown.

5
24_10_21/asd.mjs Normal file
View File

@ -0,0 +1,5 @@
import * as Modul from "./koszontes.mjs";
console.log(Modul.duplaz(2));
console.log(Modul.koszontosDuplazas("Digi", 5));

77
24_10_21/fetch_genyo.html Normal file
View File

@ -0,0 +1,77 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form>
Cím: <input type="text" id="title"> <br>
Id: <input type="number" id="id"> <br>
Befejezett: <input type="checkbox" id="completed" value="0"> <br>
</form>
<button id="bekuld">Beküld</button>
<div id="todos"></div>
<script>
let url = "https://jsonplaceholder.typicode.com/todos";
document.getElementById("bekuld").addEventListener("click", function (){
let cim = document.getElementById("title").value;
let identification = document.getElementById("id").value;
let completed = document.getElementById("completed").checked;
/*
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: identification,
title: cim,
completed: completed
}),
})
.then(response => response.json())
.then(data => {
let divelement = document.createElement("div");
let cim = document.createElement("h2");
cim.innerHTML = data.title;
let asd = document.createElement("p");
asd.innerHTML = `Az elem azonosítója: ${data.id} <br>
Az elem befejezésének állapota: ${data.completed ? "befejezve" : "nem befejezett"}`;
divelement.appendChild(cim);
divelement.appendChild(asd);
document.getElementById("todos").appendChild(divelement);
});
*/
asd();
});
async function asd() {
try{
let response = await fetch(url);
let data = await response.json();
console.log(data);
} catch (error){
console.log(error)
}
}
</script>
</body>
</html>

View File

@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="lekeres">
Adat lekérése
</button>
<div id="img_0">
</div>
<div id="img_1">
</div>
<div id="img_2">
</div>
<script>
let url = "https://jsonplaceholder.typicode.com/photos";
document.getElementById("lekeres").addEventListener("click", function () {
adatlekeres();
});
async function adatlekeres() {
try {
let response = await fetch(url);
let data = await response.json();
for (let index = 0; index < 3; index++) {
let cim = document.createElement("h2");
cim.innerHTML = data[index].title;
let element = document.createElement("img");
element.src = data[index].thumbnailUrl;
let divelement = document.getElementById(`img_${index}`);
divelement.appendChild(cim);
divelement.appendChild(element);
}
} catch (error){
console.log(error);
}
}
</script>
<!--
type modulet kell használni
<script type="module" src="scripts.mjs">
udvozlet();
</script>
-->
<script type="module" src="script.mjs">
</script>
</body>
</html>

9
24_10_21/koszontes.mjs Normal file
View File

@ -0,0 +1,9 @@
function duplaz(num) {
return num * 2;
}
function koszontosDuplazas(nev, szam){
return `Szia ${nev}! A duplázott érték: ${2 * szam}`;
}
export {koszontosDuplazas, duplaz};

8
24_10_21/script.mjs Normal file
View File

@ -0,0 +1,8 @@
import * as Modul from './scripts.mjs';
import {udvozles, valtozo} from "./scripts.mjs";
console.log(Modul.valtozo);
udvozles();

6
24_10_21/scripts.mjs Normal file
View File

@ -0,0 +1,6 @@
function udvozlet(){
console.log("Hello!");
};
let valtozo = 15;
let tomb = [1,2,3];
export {udvozlet as udvozles, valtozo, tomb};