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

114
Views
Usando javascript para guardar una entrada de texto en el almacenamiento local

Estoy tratando de usar javascript para guardar una entrada de texto usando el almacenamiento local con poco éxito. ¿Alguien podría ofrecer algún consejo, ya que soy nuevo en javascript? Es para un sitio de publicación de blog básico donde el usuario envía texto en una entrada de diario. No estoy particularmente seguro de cómo obtener el valor actual de los elementos del área de texto como se muestra en el código a continuación y creo que ahí es donde me estoy equivocando.

 function addTextEntry(itemKey, initialText, isNewEntry) { // Create a textarea element to edit the entry var textElement = document.createElement("textarea"); textElement.rows = 5; textElement.placeholder = "(new entry)"; textElement.value = initialText; addSection(itemKey, textElement); // If this is a new entry (added by the user clicking a button) // move the focus to the textarea to encourage typing if (isNewEntry) { textElement.focus(); } // Create an event listener to save the entry when it changes function saveEntry() { console.log("saveEntry called with variables in scope:", { itemKey, initialText, isNewEntry, textElement, }); // Save text entry // ...get the textarea element's current value textElement = document.getElementById; // ...make a text item using the value textElement.value = initialText; // (demonstrated elsewhere in this file) // ...store the item in local storage using the given key localStorage.setItem(itemKey); } // Connect the saveEntry evenFt listener to the textarea element 'change' event textElement.addEventListener("change", saveEntry); // (demonstrated elsewhere in this file) }

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Parece que estás usando getElementById mal.

Intente lo siguiente para obtener el valor actual de un <textarea> :

 function logTextareaValue () { const element = document.getElementById('myTextarea') const value = element.value console.log(value) }
 <textarea id="myTextarea">Default text</textarea> <button onClick="logTextareaValue()">Click to log textarea value to console</button>

about 4 years ago · Juan Pablo Isaza Report

0

En su código, está pasando solo un parámetro itemKey al método setItem() . También debe pasar el valor de esa clave como segundo parámetro.

 localStorage.setItem(itemKey, itemValue);
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!