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

427
Views
¿Cómo comprobar que existe el complemento y las funciones de jQuery?

Tengo un complemento en algunas páginas, pero en otras páginas no lo quiero, así que no hice referencia a su archivo de script.

Cómo verificar si las funciones del complemento existen antes de usarlo.

En mi caso estoy usando este plugin: y lo uso así:

 $('#marquee-inner div').marquee('pointer').mouseover(function() { $(this).trigger('stop'); }).mouseout(function() { $(this).trigger('start'); }).mousemove(function(event) { if ($(this).data('drag') == true) { this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX); } }).mousedown(function(event) { $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft); }).mouseup(function() { $(this).data('drag', false); });

Lo que quiero es hacer una verificación antes de llamar a esta función de marquesina si existe o no.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

if ($.fn.marquee) { // there is some jquery plugin named 'marquee' on your page }
over 4 years ago · Santiago Trujillo Report

0

También puedes hacer esto. Permítanme tomar el ejemplo de marquesina de jQuery.

Esto es bueno si está usando solo jQuery.

 if($().marquee) { // marquee is loaded and available }

O

 if($.fn.marquee !== undefined) { // marquee is loaded and available }

Similar al anterior pero seguro cuando está utilizando otros marcos JS, Mootools, etc.

 if(jQuery().marquee) { // marquee is loaded and available }

O

 if(jQuery.fn.marquee !== undefined) { // marquee is loaded and available }
over 4 years ago · Santiago Trujillo Report

0

Ligeramente mejor:

 if ($.isFunction($.fn.marquee)) { // ... }

Tal vez un poco exagerado, pero esto asegurará que sea al menos una función.

Actualización de enero de 2021:

Dado que jQuery.isFunction() ha quedado obsoleto a partir de la versión 3.3, la forma más fácil y recomendada de verificar esto es ahora:

 if (typeof $.fn.marquee === "function") { // ... }

Tenga en cuenta que esto puede no ser suficiente para ciertos navegadores muy antiguos; consulte la implementación de $.isFunction() para obtener más detalles.

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!