网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 jQuery判断浏览器并动态调整select宽度的方法
范文
    本文实例讲述了jQuery判断浏览器并动态调整select宽度的方法。分享给大家供大家参考,具体如下:
    <!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> 
      <title>Untitled Page</title> 
      <mce:script src="jquery-1.4.4.js" mce_src="jquery-1.4.4.js" type="text/javascript"></mce:script> 
      <mce:script type="text/javascript"><!-- 
        function userBrowser() { 
          var browserName = navigator.userAgent.toLowerCase(); 
          if (/msie/i.test(browserName) && !/opera/.test(browserName)) { 
            browserName="ie"; 
          } else if (/firefox/i.test(browserName)) { 
            browserName = "firefox"; 
          } else if (/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName)) { 
            browserName = "chrome"; 
          } else if (/opera/i.test(browserName)) { 
            browserName = "opera"; 
          } else if (/webkit/i.test(browserName) && !(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName))) { 
            browserName = "safari"; 
          } else { 
            browserName = "unknow"; 
          } 
          return browserName; 
        } 
        $(function() { 
          var browser = userBrowser(); 
          if (browser == "ie") { 
            $("select").each(function() { 
              $(this).css("width", ($(this).width() + 10) + "px"); 
            }); 
          } 
          else if (browser == "firefox") { 
            $("select").each(function() { 
              $(this).css("width", ($(this).width() + 8) + "px"); 
            }); 
          } 
          else if (browser == "chrome") { 
            $("select").each(function() { 
              $(this).css("width", ($(this).width() + 6) + "px"); 
            }); 
          } 
          else if (browser == "safari") { 
            $("select").each(function() { 
              $(this).css("width", ($(this).width() + 30) + "px"); 
            }); 
          } 
        }); 
    // --></mce:script> 
    </head> 
    <body> 
      <div> 
        <!-- 注: select 在doctype下, 会出现width比同width的text短, ie为6px, ff为4px --> 
        <input id="t1" type="text" /><br /> 
        <select id="s1"> 
          <option>1</option> 
        </select><br /> 
        <textarea id="TextArea1" cols="20" rows="2"> 
      </div>
    </body>
    </html>
    希望本文所述对大家jQuery程序设计有所帮助。
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/17 10:59:58