jQuery Plugin Check Version

前端 未结 15 907
轮回少年
轮回少年 2020-12-16 11:57

When writing a new jQuery plugin is there a straightforward way of checking that the current version of jQuery is above a certain number? Displaying a warning or logging an

相关标签:
15条回答
  • 2020-12-16 12:30
    $().jquery;
    

    or

    jQuery.fn.jquery;
    
    0 讨论(0)
  • 2020-12-16 12:32

    See my answer here: jQuery Version Compatibility Detection

    0 讨论(0)
  • 2020-12-16 12:32

    Split the jQuery version string into numbers to test their value. Some version strings do not contain an increment, so make them 0.

    var
      version = $.fn.jquery.split('.'),
      versionMinor = parseFloat(version[1]),
      versionIncrement = parseFloat(version[2] || '0');
    
    if (versionMinor === 4 && versionIncrement < 3 || versionMinor < 4) {
      $.error('Requires jQuery 1.4.3 or higher to support ...');
    }
    

    Use the jQuery error function to prevent execution with an explanation to the developer.

    0 讨论(0)
提交回复
热议问题