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)); | ||
</pre> | </pre> | ||
Zeile 25: | Zeile 35: | ||
* 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"; | ||
"abc".indexOf("bc") === 1; | "abc".indexOf("bc") === 1; | ||
"abcb".replace("b", "x") === "axcb"; | "abcb".replace("b", "x") === "axcb"; | ||
</pre> | </pre> | ||
Zeile 53: | Zeile 48: | ||
* Daher haben Ganzzahlen max. 53 Bit | * Daher haben Ganzzahlen max. 53 Bit | ||
* x=Math.min(1,2,3); r=Math.floor(x); w=Math.sqrt(x); | * x=Math.min(1,2,3); r=Math.floor(x); w=Math.sqrt(x); | ||
== Dictionary == | == Dictionary == | ||
<pre>var x = { "zahl" : 33, "pair" : { "x" : true } }; | <pre>var x = { "zahl" : 33, "pair" : { "x" : true } }; | ||
</pre> | </pre> | ||
Zeile 89: | Zeile 60: | ||
[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 83: | ||
const p = new Polygon(300, 400); | const p = new Polygon(300, 400); | ||
p.sayName(); | p.sayName(); | ||
</ | </pre> | ||