CODE EVALUIEREN
Кто подскажет правильный код? В инете информация очень размытая:
codePhrase = "{firstValue} - {secondValue} - {thirdValue}!";
array = [ "Symfony", "Java", "Our", "PHP", "Values", "C#", "JavaScript", "Are"]; if (array.contains("Our")) {
codePhrase.replace("{secondValue}", "HUMAN");
}
if (array.contains("Values")) {
codePhrase.replace("{firstValue}", "UNITED");
}
if (array.contains("Are")) {
codePhrase.replace("{thirdValue}", "GROWTH");
---------------------------------------------
Was fehlt dort?
<h1 id="text">Ergebnis</h1>
<button id="button">Klick mich!</button>
//function init() {//var elem = document.getElementById('button'); elem.addEventListener('click', replace);
//var codehrase = codephrase(firstValue, secondValue, thirdValue);
var firstValue = "UNITED";
var secondValue = "STATE";
var thirdValue = "GROWTH";
//var codePhrase = codephrase("UNITED", "STATE", "GROWTH");
var array = array("Symfony", "Java", "Our", "PHP", "Values", "C#", "JavaScript", "Are");
document.getElementById("button").onclick = function(){
if (array.includes("Our")) {
document.getElementById("text").innerHTML = "WERT" + secondValue;
}else if (array.includes("Values")) {
document.getElementById("text").innerHTML = "WERT" + firstValue;
}else (array.includes("Are")) {
document.getElementById("text").innerHTML = "WERT" + thirdValue;
}
спасибо...;))
Да уж, подозреваю что это домашнее задание на тему динамической замены содержимого элементов на html-странице. Про дополнительные навороты ничего не понятно, но надо ж с чего-то начать...
Вот рабочий код замены текста по клику, мадам может дописать туда то, что ей нужно:))
<!Doctype html>
<html lang="de-DE">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" href="./Beispiel:SELFHTML-Beispiel-Grundlayout.css" />
<title>...put your title here...</title>
<script type="text/javascript">
(function () {
function init() {
document.getElementById("button").addEventListener("click", replace);
}
function replace() {
document.getElementById("text").innerHTML = "replaced Text";
}
document.addEventListener("DOMContentLoaded",init);
}());
</script>
</head>
<body>
<h1 id="text">Ergebnis</h1>
<button id="button">Klick mich!</button>
</body>
</html>
Как я понимаю слова в array нужно заменить на другие.
<!Doctype html>
<html lang="de-DE">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>...put your title here...</title>
<script type="text/javascript">
var array = ["Symfony", "Java", "Our", "PHP", "Values", "C#", "JavaScript", "Are"];
(function () {
function init() {
document.getElementById("button").addEventListener("click", replace);
document.getElementById("text").innerHTML = array;
}
function replace() {
for (var n = 0; n < array.length; ++n) {
if ("Our" == array[n]) array[n] = "HUMAN";
else if ("Values" == array[n]) array[n] = "UNITED";
else if ("Are" == array[n]) array[n] = "GROWTH";
}
document.getElementById("text").innerHTML = array;
}
document.addEventListener("DOMContentLoaded",init);
}());
</script>
</head>
<body>
<h1 id="text">Ergebnis</h1>
<button id="button">Klick mich!</button>
</body>
</html>
По поводу других упомянутых конструкций можно ответить, если внятно сформулируете, зачем они Вам потребовались.