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

224
Views
include() no funciona en todos los navegadores

aquí hay un bloque de mi código. Funciona perfecto en firefox y chrome. Pero no en IE. Recibo el error " Object doesn't support property or method 'includes' "

 function rightTreeSwapfunc2() { if ($(".right-tree").css("background-image").includes("stage1") == true) { $(".right-tree").css({ backgroundImage: "url(/plant-breeding/img/scenes/plant-breeding/stage5.jpg)" }) } else { $(".right-tree").css({ backgroundImage: "url(/plant-breeding/img/scenes/plant-breeding/stage3.jpg)" }) } }

Podría cambiarlo un poco y usar Vanilla JS y hacer:

document.getElementById("right-tree").classList.contains

Pero preferiría ver si hay una manera de hacer que funcione en IE antes de cambiar el JS y editar el HTML y el CSS.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Si observa la documentación de includes() , la mayoría de los navegadores no admiten esta propiedad.

Puede usar indexOf() ampliamente compatible después de convertir la propiedad en una cadena usando toString() :

 if ($(".right-tree").css("background-image").indexOf("stage1") > -1) { // ^^^^^^^^^^^^^^^^^^^^^^

También puedes usar el polyfill de MDN .

 if (!String.prototype.includes) { String.prototype.includes = function() { 'use strict'; return String.prototype.indexOf.apply(this, arguments) !== -1; }; }
over 4 years ago · Santiago Trujillo Report

0

IE11 implementa String.prototype.includes, entonces, ¿por qué no usar el Polyfill oficial?

Fuente: fuente de relleno polivinílico

 if (!String.prototype.includes) { String.prototype.includes = function(search, start) { if (typeof start !== 'number') { start = 0; } if (start + search.length > this.length) { return false; } else { return this.indexOf(search, start) !== -1; } }; }
over 4 years ago · Santiago Trujillo Report

0

En mi caso encontré mejor usar "string.search".

 var str = "Some very very very long string"; var n = str.search("very");

Por si le sirve a alguien.

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!