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

242
Views
cuando una casilla no está marcada, borra el texto rellenado previamente de la casilla de verificación

¿Cómo borro el texto rellenado anteriormente de la casilla de verificación cuando desmarco la casilla?

la lista debajo de los códigos es cuando marca una casilla y completa el texto en el área de texto.

 $('input:checkbox').click(function(){ var tb = "#"+$(this).attr('rel'); if($(this).is(":checked")) $(tb).append(this.name + "\n"); else($(tb)).removeAttr(":checked"); })
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede utilizar la función replace() para eliminar el nombre del campo de texto.

 $('input:checkbox').click(function() { var tb = "#" + $(this).attr('rel'); let text_to_add = this.name + "\n"; if ($(this).is(":checked")) { $(tb).append(text_to_add); } else { let remove = this.name + "\n"; $(tb).text(function(i, text) { return text.replace(text_to_add, ''); }); } })

about 4 years ago · Juan Pablo Isaza Report

0

La siguiente secuencia de comandos reúne los valores de atributo de name de las casillas de verificación marcadas y los coloca en el cuadro de texto al que se dirige el atributo rel de la casilla de verificación:

 $('input:checkbox').click(function(){ var tb = $(this).attr('rel'); $("#"+tb).val($("[rel="+tb+"]:checked").map((i,e)=>e.name).get().join("\n")) })
 textarea {height:50px}
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <label><input name="one" type="checkbox" rel="mytext">one</label> <label><input name="two" type="checkbox" rel="mytext">two</label> <label><input name="three" type="checkbox" rel="mytext">three</label><br> <textarea id="mytext"></textarea> <br> <label><input name="four" type="checkbox" rel="text2">4</label> <label><input name="five" type="checkbox" rel="text2">5</label> <label><input name="six" type="checkbox" rel="text2">6</label><br> <textarea id="text2"></textarea>

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!