jQuery浏览器版本判断
生活随笔
收集整理的這篇文章主要介紹了
jQuery浏览器版本判断
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
jQuery 瀏覽器判斷,jQuery提供了一個 jQuery.browser 方法 來判斷瀏覽器
可用值:
safari ??opera ??msie ??mozilla?
例如:
if($.browser.msie){ alert("Microsoft Internet Explorer")}
if($.browser.mozilla){ alert("Mozilla Firefox")}
當然有時候我們還需要區分版本 這就要用到 jQuery.browser.version?
例如:
if($.browser.msie){ alert($.browser.version)}
你可能得到 6.0 ?7.0 或者其他 等等?
下面是一個較為完整的例子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> <script type="text/javascript" src="http://www.titan24.com/scripts/jquery-1.2.6.pack.js"></script> <style type="text/css"> *{ margin:0; padding:0;} body{ background:#eee;} .info{ width:600px; min-height:120px; _height:120px; line-height:120px; border:8px solid #f60; margin:40px auto; background:#fff; text-align:center; font-size:36px; font-weight:900; font-family:Arial, Helvetica, sans-serif; color:#d00;} </style> <script type="text/javascript"> /* <![CDATA[ */ $(document).ready(function(){var bro=$.browser;var binfo="";if(bro.msie) {binfo="Microsoft Internet Explorer "+bro.version;}if(bro.mozilla) {binfo="Mozilla Firefox "+bro.version;}if(bro.safari) {binfo="Apple Safari "+bro.version;}if(bro.opera) {binfo="Opera "+bro.version;}alert(binfo);$("#browser").html(binfo); }) /* ]]> */ </script> </head><body> <div id="browser" class="info"> Browser Info </div> </body> </html>?
轉載于:https://www.cnblogs.com/dudu837/archive/2010/11/11/1874685.html
總結
以上是生活随笔為你收集整理的jQuery浏览器版本判断的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【专题】CCD
- 下一篇: Delphi与SQL模糊查询(转载)