Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
Eliminar cierto texto antes de pegarlo

Tengo un evento de pegado en el que obtengo cierto texto sin formato, por lo que quiero eliminar un texto del texto copiado y pegarlo.

texto copiado en el Clipboard

 <p style="font:10pt Times New Roman, Times;" pid="123"> This Amendment contains only the Cover Page, this Explanatory Note. </p>

Entonces, quiero eliminar is pid="123" , ¿cómo puedo hacerlo?

 myTextArea.addEventListener('paste', (e) => { let html = e.clipboardData.getData('text/plain'); console.log('i pasted', html); });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede usar el patrón de expresiones regulares y el método de replace para obtener la cadena correcta. Aquí está el código:

 myTextArea.addEventListener('paste', (e) => { let html = e.clipboardData.getData('text/plain'); let transformed_html = html.replace(/pid=\"[0-9]*\"/, ""); console.log('i pasted', transformed_html); const selection = window.getSelection(); if (!selection.rangeCount) return false; selection.deleteFromDocument(); selection.getRangeAt(0).insertNode(document.createTextNode(transformed_html)); event.preventDefault(); });
about 4 years ago · Juan Pablo Isaza Report

0

Primero debe crear un elemento para cambiar los atributos.

de lo contrario, tendrá que manipular cadenas, ya sea usando bucles o Regex.

 let htmlAsText = `<p style="font:10pt Times New Roman, Times" pid="123"> This Amendment contains only the Cover Page, this Explanatory Note. </p>`; let div = document.createElement("div"); div.innerHTML = htmlAsText; div.querySelector("p").removeAttribute("pid"); document.querySelector("body").appendChild(div)

crearElemento() eliminarAtributo()

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!