jquery.extend.js 948 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // jquery 扩展支持
  2. jQuery.browser = (function () {
  3. var rwebkit = /(webkit)\/([\w.]+)/,
  4. ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
  5. rmsie = /(msie) ([\w.]+)/,
  6. rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
  7. browser = {},
  8. ua = window.navigator.userAgent;
  9. function uaMatch(ua) {
  10. ua = ua.toLowerCase();
  11. var match = rwebkit.exec(ua)
  12. || ropera.exec(ua)
  13. || rmsie.exec(ua)
  14. || ua.indexOf("compatible") < 0 && rmozilla.exec(ua)
  15. || [];
  16. return {
  17. browser: match[1] || "",
  18. version: match[2] || "0"
  19. };
  20. }
  21. var browserMatch = uaMatch(ua);
  22. if (browserMatch.browser) {
  23. browser[browserMatch.browser] = true;
  24. browser.version = browserMatch.version;
  25. }
  26. return browser;
  27. })();
  28. // 扩展size方法
  29. jQuery.fn.extend({
  30. size: function () {
  31. return this.length;
  32. }
  33. });