Cómo insertar código fuente HTML no ejecutable en una página web
Al insertar un código HTML corto en JS, primero puede encapsularlo con una función, extraer el código HTML que desea agregar y luego usar InnerHTML para extraer la función. Simplemente agregue un evento a su HTML y luego simplemente llame a esto. function.Le proporcionaré un ejemplo específico:
lt; htmlgt;
lt; scriptgt; >lt;scriptgt;
La función inserta código fuente html no ejecutable en la página web.
lt;headgt;
lt;scriptgt;
función insert(){
var insertText = "lt;tablegt;lt ;trgt;lt;tdgt;cualquier cosalt./tdgt;lt;/trgt;lt;/tablegt;";
document.getElementById("insert").innerHTML(insertText);
}
lt;/scriptgt;
lt;/headgt;
lt;bodygt;
lt;botón al hacer clic ="insert()"gt;insertlt;/buttongt;
lt;div id="insert"gt;lt;/divgt;
lt;/bodygt;
lt;/htmlgt;