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

141
Views
Poner en negrita el texto seleccionado

Tengo un archivo HTML5 y estoy tratando de crear una aplicación como Google Docs usando create-electron-app.

Tengo una etiqueta de área de texto para la entrada y estoy tratando de poner en negrita el texto que el usuario ha seleccionado. Tengo la función getSelectedText() funcionando y está devolviendo una cadena como se esperaba, pero necesito poner ese texto en negrita dentro del área de texto. Si ha utilizado Google Docs, debe saber a qué me refiero.

Aquí está el código:

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Make word documents!</title> <link rel="stylesheet" href="index.css" /> </head> <body> <textarea class="userInput"></textarea> <input type="button" value="Bold" onmousedown="bold()"> <script> function getSelectedText() { if (window.getSelection) { return "" + window.getSelection(); } else if (document.selection && document.selection.type == "Text") { return document.selection.createRange().text; } return ""; } function bold() { var userInput = getSelectedText(); // userInput.style.fontWeight = "bold"; // print the type of the userinput variable console.log(typeof userInput); } </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

PreguntaSign in to vote

0

Regístrese para votar

Usuario1937363675 publicado

hola francisco

En realidad, creo que deberías usar "span" en lugar de "textarea", porque de acuerdo con algunos materiales, Web Editor casi usa span. Escribí un breve ejemplo para ti, ¡espero que pueda ayudarte!

--------------

<html>
<cabeza>
<lenguaje de script="javascript">
prueba de función (e)
{
mitexto.innerHTML="<b>"+mitexto.innerText+"</b>";
}


</script>
</cabeza>
<cuerpo>
<span contenteditable id="mytext" style="height:200;width:95%;border:1px solid black">
Editor HTML
</span>
<tipo de entrada="botón" valor="Negrita" onclick="prueba()" />
</cuerpo>


</html>

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!