Este artículo describe la diferencia entre InnerHTML y PasteHTML en JS. Compártelo para su referencia, como sigue:
InnerHTML es un atributo que puede obtener o establecer el contenido HTML en este elemento. Puede ser utilizado por cualquier elemento que pueda contener nodos infantiles HTML.
Pastehtml () es un método que reemplaza el texto o html dentro del área de texto especificado. Este método debe aplicarse a un creadoTextrange () o document.selection.CreaterGe ()
ejemplo:
<Script language = "javaScript"> function addlink () {var naranja = document.selection.createrange (); if (naranja.text! = '') {var ourl = window.promppt ('Link url ...', 'http: //www.163.com/'); var ohtml = '<a href ='+ourl+'target = _blank>'+naranja.text+'</a>'; naranja.pastehtml (ohtml); } else {Window.alert ('¡No seleccionó el texto para enlace!'); }} </script> NetEase Sina Sohu <br> <br> <input type = "button" value = "add link" onClick = "addlink ();">For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript Algoritmos y técnicas de recorrido ", y" Resumen del uso de operaciones matemáticas de JavaScript "
Espero que este artículo sea útil para la programación de JavaScript de todos.