duankan8739 2013-08-27 13:25
浏览 53
已采纳

使用链接交换jquerymobile的样式表

I have a variable called $cat(which stands for 'category') in the URL.

Depending on whether it is "a" or "b" I swap the stylesheet using a link:

<?php
if($cat == "a") { ?> 
   <link rel="stylesheet" href="/css/styleA.css"> 
<?php }
elseif($cat == "b") { ?>
   <link rel="stylesheet" href="/css/styleB.css"> 
<?php } ?>

styleA.css makes the background-color of the header blue, and styleB.css makes it red

<div id="header" data-role="header" data-position='fixed'>...</div>

if I click on a link that looks like this:

<a href="index.php?cat=a">Click for red</a>
<a href="index.php?cat=b">Click for blue</a>

the URL actually works (content is incuded depending on $cat) and I do get the value of $cat but the stylesheet does not seem to have swapped, since the color doesn't change. But if I reload the page (with the URL given by the link before) the stylesheets swap and everything works perfectly.

I used the same method for the desktop version of the website I'm working on and everything works perfectly fine. This issue seems to only appear if I use jquery mobile.

Does anyone see why this isn't working as it should?

EDIT (adding html): This is pretty much it, but here's the rest of it:

headpart:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title></title>
<link rel="stylesheet" href="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.css">
<!-- Extra Codiqa features -->
<link rel="stylesheet" href="/css/codiqa.ext.css">
<link rel="stylesheet" href="/css/style.css">
<?php if($cat == "a") { ?>  <link rel="stylesheet" href="/css/styleASS.css"> <?php } 
      if($cat == "b")   { ?> <link rel="stylesheet" href="/css/styleBB.css"> <?php }
?>
<!-- jQuery and jQuery Mobile -->
<script src="https://d10ajoocuyu32n.cloudfront.net/jquery-1.9.1.min.js"></script>
<script src="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<!-- Extra Codiqa features -->
<script src="https://d10ajoocuyu32n.cloudfront.net/codiqa.ext.js"></script>
</head>


<div data-role="page" id="page">
   <div id="panel_menu" data-role="panel" data-display="overlay">
        <ul data-role="listview">
            <li role="heading">Navigation</li>
            <li><a href="#">Home</a></li>
            <li><a href="#">Products</a></li>
            <li><a href="#">Service</a></li>
            <li><a href="#">Contact</a></li>
            <li><a href="#">Login</a></li>
        </ul>
    </div>
    <div id="header" data-role="header" data-position='fixed'>
        <h1>Header</h1>
        <a href="#panel_menu">Menu</a>
    </div>
     <div data-role="content">

     <?php include "$menu_page_content";?>

     <a href="?cat=a&lang=en&menu=home">a</a>
      <a href="?cat=b&lang=en&menu=home">b</a>

    </div>
    <div data-role="footer" data-position="fixed" data-theme="d">
        <div data-role="navbar" class="ui-icon-nodisc">
          <ul>
            <li><a href="#" id='language' data-icon='custom'>Change Language</a></li>
            <li><a href="#" id='category' data-icon="custom" >Change Category</a></li>
            <li><a href="#" id='contact' data-icon="custom" >Contact</a></li>
          </ul>
        </div>
    </div>
</div><!-- page -->

EDITIT: Uploaded it to a free hoster: here You may either click on one of the links in the content area, or on "category" in the footer area. Click & reload the page.

  • 写回答

2条回答 默认 最新

  • dsfs587465 2013-08-27 14:07
    关注

    If most of your styles are the same with the exception of the color I would suggest putting them in a single style sheet and writing in a class to the body.

    For Example

     .header {
          /* general header styles margins paddings and whatnot */
     }
    
     .cat-a .header {
          background-color: red;
     }
     .cat-b .header {
          background-color: blue;
     }
    

    Then variably write the class in on the body

     <body class='cat-<?php echo $cat; ?>'>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)