jQuery Plugin Check Version

前端 未结 15 909
轮回少年
轮回少年 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:19

    Instead of using parseInt as i saw in one of the answers above i would suggest to use parseFloat as mentioned below

      var _jQueryVer = parseFloat('.'+$().jquery.replace(/\./g, ''));
      /* Here the value of _jQueryVer would be 0.1012 if the jQuery version is 1.0.12
         which in case of parseInt would be 1012 which is higher than 
         140 (if jQuery version is 1.4.0) 
      */
      if(_jQueryVer < 0.130) { 
        alert('Please upgrade jQuery to version 1.3.0 or higher');
      }
    

提交回复
热议问题