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

89
Views
jquery .find() para buscar uno de dos valores diferentes

Tengo una tabla y la estoy haciendo editable. Al hacer doble clic en una celda, hago que la celda sea editable y, al hacer clic fuera, la revierto con el valor actualizado.

 tableCells.dblclick(function() { cell=$(this) value=cell.text(); editing=true; rowIndex = cell.parent().index('table tbody tr'); tdIndex = cell.index('table tbody tr:eq('+rowIndex+') td'); switch(tdIndex) { case 1: case 2: case 9: cell.html('<input type="text" value="'+value+'">'); break; case 3: cell.html('<select name="dob" id="dob" class="form-control"><option value="1">Uomo</option><option value="2">Donna</option></select>'); break; case 4: let temp = value.split('/'); value=temp[2]+'-'+temp[1]+'-'+temp[0]; cell.html('<input type="date" value="'+value+'">'); break; } }); $(document).click(function(e) { //se clicco fuori dalla tabella if(editing){ if (!tableCells.toArray().some(f => f.contains(e.target))) { let row = cell.parent('tr').data('row'); //la riga da aggiornare nel db updValue=cell.find('input').val(); if(e.target.cellIndex==4){ let temp=updValue.split('-'); updValue=temp[2]+'/'+temp[1]+'/'+temp[0]; } console.log(updValue); console.log('riga '+row); cell.html(updValue); editing = false; } } })

este updValue=cell.find('input').val(); funciona bien para los campos donde tengo una entrada. Pero en una situación, reemplazo la celda con una selección. ¿Cómo puedo agregar la situación select a este código de la manera más ligera? Siempre tendré solo entrada o seleccionaré solo editar la tabla. En pseudocódigo diría .find('input'||'select') . No quiero tener que agregar una clase o un atributo de nombre, sino seguir buscando el tipo de etiqueta (ingresar o seleccionar)

Lo he intentado con .find('input','select') pero no estoy definido de esta manera

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

0

Puede agregar clases a esas entradas/selecciones y luego cell.find('.myInput') o usar esto, suponga que tiene el atributo de name cell.find('[name]')

O bien, la solución es: cell.find('select, input')

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!