Bearbeiten von „JavaScript“
Zur Navigation springen
Zur Suche springen
Warnung: Du bist nicht angemeldet. Deine IP-Adresse wird bei Bearbeitungen öffentlich sichtbar. Melde dich an oder erstelle ein Benutzerkonto, damit Bearbeitungen deinem Benutzernamen zugeordnet werden.
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 1: | Zeile 1: | ||
[[Kategorie:Sprache | [[Kategorie:Sprache]] | ||
= | = DOM-Elemente finden = | ||
<pre>var list = document.getElementsByTagName("UL")[0]; | |||
var elem = document.getElementById("xyz"); | |||
</pre> | </pre> | ||
= | = Einbindung in HTML = | ||
<pre> <button onclick="myFunction()">Click me</button> | |||
</pre> | |||
<pre><p onclick="myFunction()">Click me to change my text color.</p> | |||
<script> | |||
function myFunction() { | |||
document.getElementById("demo").style.color = "red"; | |||
} | |||
</pre> | |||
<pre><button onclick="myFunction()">Copy Text</button> | |||
<script> | |||
function myFunction() { | |||
document.getElementById("text2").value = document.getElementById("text2").value; | |||
document.getElementById("textarea2").innerHTML = document.getElementById("textarea2").innerHTML; | |||
var field = document.getElementById("field1"); | |||
field.style.visibility = field.style.visibility == "hidden" ? "visible" : "hidden"; | |||
} | |||
</script> | |||
</pre> | |||
= Methoden = | |||
<pre>var hypotenuse = function(a,b) { return Math.sqrt(a*a+b*b); } | <pre>var hypotenuse = function(a,b) { return Math.sqrt(a*a+b*b); } | ||
console.log(hypotenuse(1, 44)); | console.log(hypotenuse(1, 44)); | ||
Zeile 25: | Zeile 43: | ||
* a == b: Referenzvergleich | * a == b: Referenzvergleich | ||
* a === b: Inhaltsvergleich | * a === b: Inhaltsvergleich | ||
= Typen = | = Typen = | ||
== String == | == String == | ||
<pre>text += "."; | <pre>text += "."; | ||
"xyz".substr(1, 2) === "y"; | "xyz".substr(1, 2) === "y"; | ||
Zeile 44: | Zeile 55: | ||
"abc".length === 3; | "abc".length === 3; | ||
"abc".charAt(1) == "b"; | "abc".charAt(1) == "b"; | ||
" abc ".trim() = "abc"; | " abc ".trim() = "abc"; | ||
</pre> | </pre> | ||
Zeile 75: | Zeile 84: | ||
== Dictionary == | == Dictionary == | ||
<pre>var x = { "zahl" : 33, "pair" : { "x" : true } }; | <pre>var x = { "zahl" : 33, "pair" : { "x" : true } }; | ||
</pre> | </pre> | ||
Zeile 89: | Zeile 93: | ||
[1, 3, 5, 9].slice(0,2) === [1, 3] && [1, 3, 5, 9].slice(2,3) === [3]; | [1, 3, 5, 9].slice(0,2) === [1, 3] && [1, 3, 5, 9].slice(2,3) === [3]; | ||
[3, 9, 12].join(" ") === "3 9 12"; | [3, 9, 12].join(" ") === "3 9 12"; | ||
</pre> | </pre> | ||
= Klassen = | = Klassen = | ||
< | <pre>'use strict'; | ||
'use strict'; | |||
class Polygon { | class Polygon { | ||
constructor(height, width) { | constructor(height, width) { | ||
Zeile 119: | Zeile 116: | ||
const p = new Polygon(300, 400); | const p = new Polygon(300, 400); | ||
p.sayName(); | p.sayName(); | ||
</ | </pre> | ||