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

293
Views
El código no se ejecuta en IE 11, funciona bien en Chrome

El siguiente código se puede ejecutar sin problemas en Chrome, pero arroja el siguiente error en Internet Explorer 11.

El objeto no admite la propiedad o el método 'startsWith'

Estoy almacenando la identificación del elemento en una variable. ¿Cual es el problema?

 function changeClass(elId) { var array = document.getElementsByTagName('td'); for (var a = 0; a < array.length; a++) { var str = array[a].id; if (str.startsWith('REP')) { if (str == elId) { array[a].style.backgroundColor = "Blue"; array[a].style.color = "white"; } else { array[a].style.backgroundColor = ""; array[a].style.color = ""; } } else if (str.startsWith('D')) { if (str == elId) { array[a].style.backgroundColor = "Blue"; array[a].style.color = "white"; } else { array[a].style.backgroundColor = ""; array[a].style.color = ""; } } } }
 <table> <tr> <td id="REP1" onclick="changeClass('REP1');">REPS</td> <td id="td1">&nbsp;</td> </tr> <tr> <td id="td1">&nbsp;</td> <td id="D1" onclick="changeClass('D1');">Doors</td> </tr> <tr> <td id="td1">&nbsp;</td> <td id="D12" onclick="changeClass('D12');">Doors</td> </tr> </table>

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

String.prototype.startsWith es un método estándar en la versión más reciente de JavaScript, ES6.

Mirando la tabla de compatibilidad a continuación, podemos ver que es compatible con todas las principales plataformas actuales, excepto las versiones de Internet Explorer.

 ╔═══════════════╦════════╦═════════╦═══════╦═══════════════════╦═══════╦════════╗ ║ Feature ║ Chrome ║ Firefox ║ Edge ║ Internet Explorer ║ Opera ║ Safari ║ ╠═══════════════╬════════╬═════════╬═══════╬═══════════════════╬═══════╬════════╣ ║ Basic Support ║ 41+ ║ 17+ ║ (Yes) ║ No Support ║ 28 ║ 9 ║ ╚═══════════════╩════════╩═════════╩═══════╩═══════════════════╩═══════╩════════╝

Deberá implementar .startsWith usted mismo. Aquí está el polifill :

 if (!String.prototype.startsWith) { String.prototype.startsWith = function(searchString, position) { position = position || 0; return this.indexOf(searchString, position) === position; }; }
over 4 years ago · Santiago Trujillo Report

0

text.indexOf("newString") es el mejor método en lugar de startsWith .

Ejemplo:

 var text = "Format"; if(text.indexOf("Format") == 0) { alert(text + " = Format"); } else { alert(text + " != Format"); }
over 4 years ago · Santiago Trujillo Report

0

Si esto sucede en la aplicación Angular 2+, puede descomentar los polyfills de cadena en polyfills.ts :

 import 'core-js/es6/string';
over 4 years ago · Santiago Trujillo 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!