jQuery Plugin Check Version

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

    I feel like all the solutions are rather bulky, is mine below missing something?

    Compressed version:

    (parseInt(jQuery.fn.jquery.split('.').join('')) > 140) ? alert("Running jquery greater than 1.4.0") : alert("current jquery version is 1.4.0 or less");
    

    Long version for clarity:

    // get version as a string and get rid of the periods. 
    version = jQuery.fn.jquery.split('.').join('');
    
    // Make into one long number for easy comparison.  Example, 171, or 141.
    version = parseInt(version);
    if(version > 141){
        alert("We're using a version greater than 1.4.1");
    }else{
        alert("jQuery version is 1.4.1 or lower");
    }
    

提交回复
热议问题