JavaScript - Foreach+GetElementbyID

 
Vista:
Imágen de perfil de xve
Val: 3.162
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Foreach+GetElementbyID

Publicado por xve (2100 intervenciones) el 29/08/2018 15:36:15
Hola María, este es el código que tu nos indicas:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<html>
<body>
<button onclick="myFunction()">Click me</button>
<button onclick="myFunction2()">Click me</button>
<button onclick="myFunction3()">Click me</button>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
</body>
</html>
<script>
var a = 0;
var b=0
var d= 0;
 
function myFunction() {
 
  a = a + 5;
  document.getElementById("demo1").textContent = a;
}
</script>
 
 
 
<script>
function myFunction2() {
  d = d + 5;
  document.getElementById("demo2").innerHTML = d;
}
</script>
 
<script>
function myFunction3() {
  b = b + 5;
  document.getElementById("demo3").innerHTML = b;
}
</script>


Esta es otra implementación:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<html>
<body>
<button onclick="myFunction('demo1')">Click me</button>
<button onclick="myFunction('demo2')">Click me</button>
<button onclick="myFunction('demo3')">Click me</button>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
</body>
</html>
<script>
function myFunction(id) {
  elemento=document.getElementById(id)
  elemento.textContent=parseInt(elemento.textContent)+5 || 5;
}
</script>

Te sirve?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Foreach+GetElementbyID

Publicado por María (12 intervenciones) el 29/08/2018 16:40:48
Muchísimas gracias!!!!!!! Le estaré eternamente agradecida!! :)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar