当前位置:编程学习 > JS >>

jquery macth正则表达式实例

下面我们利用jquery.macth来做实例,验证用户的浏览器为什么型的。代码如下。

rwebkit = /(webkit)[ /]([w.]+)/,
ropera = /(opera)(?:.*version)?[ /]([w.]+)/,
rmsie = /(msie) ([w.]+)/,
rmozilla = /(mozilla)(?:.*? rv:([w.]+))?/,
// keep a useragent string for use with jquery.browser
useragent = navigator.useragent,

uamatch: function( ua ) {
ua = ua.tolowercase();

var match = rwebkit.exec( ua ) ||
ropera.exec( ua ) ||
rmsie.exec( ua ) ||
ua.indexof("compatible") < 0 && rmozilla.exec( ua ) ||
[];

return { browser: match[1] || "", version: match[2] || "0" };
}
browsermatch = jquery.uamatch( useragent );
if ( browsermatch.browser ) {
jquery.browser[ browsermatch.browser ] = true;
jquery.browser.version = browsermatch.version;
}

补充:网页制作,jquery 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,