JavaScript - event.target

 
Vista:
sin imagen de perfil

event.target

Publicado por Julio Cesar (16 intervenciones) el 28/12/2017 00:17:11
Porque no me salta el alert?

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html>
<head>
	<title>CALCULADORA</title>
	<style>
    body{
    	font-family: sans-serif;
    	background-color: #123;
    }
    #calculadora{
    	background-color: #125;
    	width: 250px;
    	height: 350px;
    	border: 4px solid #fff;
    	display: flex;
    	justify-content: center;
    	align-content: flex-start;
    	flex-wrap: wrap;
    	margin: auto;
    }
 
    #display{
    	width: 230px;
    	height: 40px;
    	background-color: #000;
    	color: #fff;
    	border: 1px solid #fff;
    	font-size: 2em;
    	margin-top: 3px;
    	margin-bottom: 3px;
    	text-align: right;
    }
 
    .numero, .punto{
    	width: 55px;
    	height: 55px;
    	margin: 2px;
    }
 
    .operadores{
      	width: 55px;
    	height: 55px;
    	margin: 2px;
    }
 
    .nose, .rst{
      	width: 55px;
    	height: 55px;
    	margin: 2px;
    }
 
    .igual{
    	width: 114px;
    	height: 55px;
    	margin: 2px;
    	font-size: 3em;
    }
 
    input{
    	font-size: 2em;
    }
 
</style>
<script>
function comenzar(){
    var botnum=document.querySelectorAll('.numero');
    for(var i=0;i<10;i++){
        botnum[i].addEventListener("click",display_numeros,false);
    }
}
 
function display_numeros(event){
    alert(event.target.value);
}
 
document.addEventListener("load",comenzar,false);
</script>
 
</head>
<body>
 
<div id="calculadora">
<input type="text" id="display">
<input type="button" class="operadores" value="+">
<input type="button" class="operadores" value="-">
<input type="button" class="operadores" value="x">
<input type="button" class="operadores" value="÷">
<input type="button" class="numero" value="9">
<input type="button" class="numero" value="8">
<input type="button" class="numero" value="7">
<input type="button" class="rst" value="R">
<input type="button" class="numero" value="6">
<input type="button" class="numero" value="5">
<input type="button" class="numero" value="4">
<input type="button" class="nose">
<input type="button" class="numero" value="3">
<input type="button" class="numero" value="2">
<input type="button" class="numero" value="1">
<input type="button" class="nose">
<input type="button" class="numero" value="0">
<input type="button" class="punto" value=".">
<input type="button" class="igual" value="=">
</div>
<script>
document.getElementById("display").value=0;
</script>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de ScriptShow
Val: 2.019
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

event.target

Publicado por ScriptShow (692 intervenciones) el 28/12/2017 03:06:43
Saludos,

Prueba así:

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<head>
<title>CALCULADORA</title>
<style>
body{
font-family: sans-serif;
background-color: #123;
}
#calculadora{
background-color: #125;
width: 250px;
height: 350px;
border: 4px solid #fff;
display: flex;
justify-content: center;
align-content: flex-start;
flex-wrap: wrap;
margin: auto;
}
#display{
width: 230px;
height: 40px;
background-color: #000;
color: #fff;
border: 1px solid #fff;
font-size: 2em;
margin-top: 3px;
margin-bottom: 3px;
text-align: right;
}
.numero, .punto{
width: 55px;
height: 55px;
margin: 2px;
}
.operadores{
width: 55px;
height: 55px;
margin: 2px;
}
.nose, .rst{
width: 55px;
height: 55px;
margin: 2px;
}
.igual{
width: 114px;
height: 55px;
margin: 2px;
font-size: 3em;
}
input{
font-size: 2em;
}
</style>
<script>
onload=function(){
var botnum=document.getElementsByTagName("input");
for(var i=0;i<20;i++){
botnum[i].onclick=function(){alert(this.value)}
}
}
</script>
</head>
<body>
<div id="calculadora">
<input type="text" id="display">
<input type="button" class="operadores" value="+">
<input type="button" class="operadores" value="-">
<input type="button" class="operadores" value="x">
<input type="button" class="operadores" value="÷">
<input type="button" class="numero" value="9">
<input type="button" class="numero" value="8">
<input type="button" class="numero" value="7">
<input type="button" class="rst" value="R">
<input type="button" class="numero" value="6">
<input type="button" class="numero" value="5">
<input type="button" class="numero" value="4">
<input type="button" class="nose">
<input type="button" class="numero" value="3">
<input type="button" class="numero" value="2">
<input type="button" class="numero" value="1">
<input type="button" class="nose">
<input type="button" class="numero" value="0">
<input type="button" class="punto" value=".">
<input type="button" class="igual" value="=">
</div>
<script>
document.getElementById("display").value=0;
</script>
</body>
</html>

Espero sea útil.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
2
Comentar
sin imagen de perfil

event.target

Publicado por Julio Cesar (16 intervenciones) el 28/12/2017 03:18:55
Si me sirvió, gracias, y ya encontre mi error.
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