-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteste.html
71 lines (68 loc) · 1.76 KB
/
teste.html
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
<!DOCTYPE html>
<html>
<head>
<title>Cadastro em Tabela</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 5px;
text-align: center;
}
th {
background-color: gray;
color: white;
font-weight: bold;
}
</style>
</head>
<body>
<h1>Cadastro em Tabela</h1>
<table>
<thead>
<tr>
<th>Nome</th>
<th>E-mail</th>
<th>Telefone</th>
</tr>
</thead>
<tbody>
<!-- Aqui serão adicionados os registros -->
</tbody>
</table>
<br>
<h2>Adicionar Registro</h2>
<form onsubmit="adicionarRegistro()">
<label>Nome:</label>
<input type="text" id="nome"><br><br>
<label>E-mail:</label>
<input type="email" id="email"><br><br>
<label>Telefone:</label>
<input type="tel" id="telefone"><br><br>
<input type="submit" value="Adicionar">
</form>
<script>
function adicionarRegistro() {
// Captura os valores dos campos do formulário
var nome = document.getElementById("nome").value;
var email = document.getElementById("email").value;
var telefone = document.getElementById("telefone").value;
// Cria uma nova linha na tabela com os valores capturados
var tabela = document.getElementsByTagName("tbody")[0];
var novaLinha = tabela.insertRow(-1);
var colunaNome = novaLinha.insertCell(0);
var colunaEmail = novaLinha.insertCell(1);
var colunaTelefone = novaLinha.insertCell(2);
colunaNome.innerHTML = nome;
colunaEmail.innerHTML = email;
colunaTelefone.innerHTML = telefone;
// Limpa os valores dos campos do formulário
document.getElementById("nome").value = "";
document.getElementById("email").value = "";
document.getElementById("telefone").value = "";
// Impede que o formulário seja enviado
return false;
}
</script>
</body>
</html>