2011-12-29 59 views
-4

我有一些代码用于在移动设备上显示jQuery手机和其他一些代码,以及在常规计算机上显示jQuery和一些其他代码。我听说最好在jQuery mobile之前加入jQuery代码,所以我想知道如何切换if/else语句,以便常规计算机代码是第一个。最好是看到我的代码编辑版本的这个问题。需要if/else切换

<?php $mobile_browser = '0'; if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) { $mobile_browser++; } if ((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') > 0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) { $mobile_browser++; } $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4)); $mobile_agents = array('w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac', 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno', 'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-', 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-', 'newt','noki','oper','palm','pana','pant','phil','play','port','prox', 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar', 'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-', 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp', 'wapr','webc','winw','winw','xda ','xda-'); if (in_array($mobile_ua,$mobile_agents)) { $mobile_browser++; } if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini') > 0) { $mobile_browser++; } if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows') > 0) { $mobile_browser = 0; } if ($mobile_browser > 0) { ?> 
    <link href="http://www.luvbid.com/css/mobilestyle.css" type="text/css" rel="stylesheet" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" /> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> 
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script> 
    <script> 
     $('div').bind('pageinit', function() { 
      $(this).find('a').bind('click', function(e) { 
       e.preventDefault(); 
       //add your custom ajax call here 
      }); 
     }); 

    </script> 
    <? } else { ?> 
    <link href="http://www.luvbid.com/css/style.css" type="text/css" rel="stylesheet" /> 
    <script src="http://cdn.jquerytools.org/1.2.6/jquery.tools.min.js"></script> 
    <link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/smoothness/jquery-ui.css" /> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script> 
    <script src="js/jquery.alerts.js"></script> 
    <script src="http://cdn.jquerytools.org/1.2.6/form/jquery.tools.min.js"></script> 
    <? } ?> 
+1

这算作编辑...: ( – Prescott 2011-12-29 01:38:48

+0

只是有点难以阅读,大多数人都通过它 – Prescott 2011-12-29 01:43:33

+2

你有3个问题,没有积极的或0代表,与评论,遵循相同的主题;你问我们的_solution_你的问题,何时实际上,SO在这里帮助你病房解决问题。请注意评论的意见和重构未来的问题。 – Bojangles 2011-12-29 01:45:25

回答

1

变化的代码,第一行的最后部分说,而不是

if ($mobile_browser <= 0) 

if ($mobile_browser > 0) 

,你应该在企业。不过,别忘了将所有的包括和东西以及:)

0
​​3210

成为

if ($mobile_browser <= 0)... 

,但这不会真正帮助你为引用的移动版本将只输出后的代码表达进行评估。这发生在服务器端,与客户端浏览器的性能无关。

0
在碎裂开来的第一行所有的语句

目前,它看起来像这样:

<?php $mobile_browser = '0'; 
if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) { $mobile_browser++; } 
if ((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') > 0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) { $mobile_browser++; } 
$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4)); 
$mobile_agents = array('w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac', 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno', 'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-', 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-', 'newt','noki','oper','palm','pana','pant','phil','play','port','prox', 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar', 'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-', 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp', 'wapr','webc','winw','winw','xda ','xda-'); if (in_array($mobile_ua,$mobile_agents)) { $mobile_browser++; } 
if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini') > 0) { $mobile_browser++; } 
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows') > 0) { $mobile_browser = 0; } 
if ($mobile_browser > 0) { ?> 

改变最后的if语句这样:

if ($mobile_browser == 0)