index.php?id=89
Por Yal Publicidad
Publicado el Mar 9 de Julio del 2019 a las 15:13
El método Document.createElement() crea un elemento HTML especificado por su tagName, o un HTMLUnknownElement si su tagName no se reconoce.
var element = document.createElement(tagName, [options]);
En este ejemplo vamos a crear un formulario simple para subir imágenes al servidor:
<!DOCTYPE html> <html> <head> <title>Crear Elementos HTML con JavaScript</title> </head> <body> <form enctype="multipart/form-data" method="post">
<button type="button" onclick="add_file_img()">+ Agregar imagen</button>
<div id="div1">Aquí de agregarán los input para examinar imágenes.</div> </form> </body> </html>
function add_file_img(){
$contenedor = document.getElementById('div1');
var $imagen_nueva = document.createElement('input');
$imagen_nueva.setAttribute( "type", "file" );
$imagen_nueva.setAttribute( "name", "imagenes[]" );
$contenedor.appendChild( $imagen_nueva );
}