1
I need to create an HTML document where the user can add names to a numbered list (OL). Your document must have a text box (an input for typing text) where the user can enter one name at a time. In addition, it should have a button labeled "Add", which when clicked adds the typed text to the OL list. The user can add as many names as he wants and each name is added at the end of the OL list. However, at any time of execution, the user can sort the names of the OL list by clicking on a button labeled "Sort List". The user click on the "Sort List" button, it should be regrouped in an orderly manner. Use the sorting algorithm of your choice (Bubble, Insertion, Quick, etc).
z códico it at the time of sorting I think identifies the escaço as another variable and divides.
<!doctype HTML>
<html>
<head>
<title>Eventos em javascript</title>
<meta charset="utf-8" >
<script>
var arr = [];
function adicionar(){
var nome = document.getElementById("nome");
lista.innerHTML = lista.innerHTML + "<li>" + nome.value + "</li>";
arr = arr + nome.value + " ";
}
function ordenar(){
document.getElementById("lista").innerHTML = "";
var iv = arr.split(" ");
iv.pop();
iv.sort();
for (var i = 0 ; i < iv.length ; i++)
{
lista.innerHTML = lista.innerHTML + "<li>" + iv + "</li>";
}
}
</script>
</head>
<body>
<header>
<h3>Lista de Nomes</h3>
</header>
<input id="nome" type="text">
<button onclick="adicionar()">Adicionar</button>
<ol id="lista">
</ol>
<button onclick="ordenar()">Listar por ordem alfabética</button>
<div class="col-sm-10">
</div>
</body>
</html>
– Luiz Vichiatto