JavaScript - Eliminar eleementos

 
Vista:

Eliminar eleementos

Publicado por ana (1 intervención) el 13/10/2016 06:45:23
Es para una tarea tengo que
Mostrar un cuadro de texto, en el cual el usuario introducirá el número de la lista <ol> a eliminar. En caso de encontrarse fuera de rango, mostrar mensaje de error.
o
Mostrar un combobox con el número de elementos <li> que se encuentren en la lista, el llenado del combobox debe ser dinámico, es decir, de acuerdo al número de <li>.
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title> Nombre de la pagina</title>
</head>
<body>
   <!--    <div id="combo">-->
    <select name="" id="op" onchange="creacion();">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
 
     <button id="borrar" onclick="borrar();">Borrar</button>
      <!--</div>-->
      <div id="contenedor"></div>
 
      <button id="agregar" onclick="agregar();">agregar elemento</button>
       <ul class="lista" id="lista">
           <li>item 1</li>
           <li>item 2</li>
           <li>item 3</li>
       </ul>
   <button onclick="numli()">numero de lista</button>
   <div id="uno">
       <a id="link"></a>
   </div>
 
        <script>
 
 function numli (){
             var numero;
 
            do{
                numero=Number(prompt("Ingresa un numero de la lista a eliminar "));
              }while(numero=0 || numero<= lista.children.length -1 || i++);
 
            if (isNaN(numero.value)==true) {
                alert("numero no valido");
                javascript:location.reload();
            }
 
        function eliminar()
     {
 
         document.getElementById("numero").
     }
 
 
console.log(typeof numero);
          console.log(numero);
 
       }
 
            document.getElementById("op").addEventListener("onchange",creacion);
            function creacion(){
                var padre = document.getElementById("contenedor");
                var num= document.getElementById("op").value;
 
                for (i=1; i<=num; i++){
                    var hijo=document.createElement("p");
                    var contenido = document.createTextNode("cadena de numero: "+i);
                    hijo.setAttribute("id",i);
                    hijo.appendChild(contenido);
                    padre.appendChild(hijo);
                }
 
            }
 
            function borrar(){
                padre=document.getElementById("contenedor");
                padre.removeChild(padre.childNodes[0]);
            }
 
            function agregar(){
                padre2 = document.getElementsByTagName("ol")[0];
                ultimo = document.getElementsByTagName("li");
                elemento.appendChild(contenido);
 
                padre2.insertBefore(hijo2,ultimo[ultimo.length-1]);
                contador++;
            }
 
        </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