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

156
Views
¿Manera elegante de establecer el ancho css del elemento para que se ajuste a 'la mayoría' del contenido? por un patrón de expresiones regulares?

Tengo un elemento <select> y elementos <option> .

En lugar de codificar el width a 90px , estoy buscando una manera de establecer el ancho para que se ajuste a una porción de expresiones regulares del contenido <option>

La expresión regular preferida sería LOREMIPSUM#\d{0,5}

En otras palabras,

  • ¿Hay alguna manera de que el max-width min-width de <select> se ajusten bien solo a la parte LOREUMIPSUM#?
  • No quiero que el ancho de <select> se ajuste a todo el contenido, solo la primera parte de ese patrón de expresión regular.
 <select id="someId" name="someName" class="someClass" size="1" onchange="someMethod();" style="width:90px;"> <option value="a0D3u00000BhNCxEAN">LOREMIPSUM#0263 abcabcabcabcabcabcabcabcabcabcabcabc</option> <option value="a0D3u00000Bh7qFEAR">LOREMIPSUM#0262 user tests</option> <option value="a0D3u00000BgovaEAB">LOREMIPSUM#0258 dogs</option> <option value="a0D3u00000BgovVEAR">LOREMIPSUM#0257 cats</option> <option value="a0D3u00000BgovVEAR">LOREMIPSUM#10000 some text</option> </select>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que algo como lo siguiente podría funcionar. Sin probar

 var myOpts = document.getElementById('someId').options; function biggestNumberInArray(arr) { const max = Math.max(...arr); return max; } var subTextLengths=[]; Array.from(document.querySelector("#someId").options).forEach(function(option_element) { let option_text = option_element.text; //let option_value = option_element.value; let regex = new RegExp('LOREMIPSUM#\d{0,5}'); let subText = regex.exec(option_text); let subTextLength = subText.length; subTextLengths.push(subTextLength); }); document.getElementById('someId').style.width = biggestNumberInArray(subTextLengths);
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!