如何使jQuery Mobile仅影响一页 [英] How to make jQuery Mobile only affect one page

查看:88
本文介绍了如何使jQuery Mobile仅影响一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我创建的网站中,我使用的是jQuery Mobile,尽管我对此并不了解,但我遇到了一个大问题.在我的网站中,我仅链接到一页上的jQuery Mobile,而我只想在一页上使用jQuery Mobile(我不知道是否可以,但这就是我想要的).

我的网站上有四个主页:Homepage.php,SalesForms.php,Reports.php和Login.php.我只想在Reports.php页面上使用jQuery Mobile(我正在使用它进行过渡,以创建漂亮的html表单过程).

每当我转到Reports.php页面时,它都使用jQuery Mobile和jQuery以及jQuery Mobile CSS,这很好.但是,当我离开Reports.php页面并转到其他页面时,即使仍未使用jQuery Mobile及其CSS,即使这些页面未链接到jQuery Mobile及其CSS. >

例如,当我访问Homepage.php时,它未使用jQuery Mobile或其CSS,然后访问了使用jQuery Mobile及其CSS的Reports.php,然后又访问了Homepage.php,它仍然使用jQuery Mobile及其CSS.这对我来说是个问题,因为jQuery Mobile的CSS会干扰Reports.php页面以外的页面上的CSS,这是它唯一链接到的页面.

我想知道是否以及如何使jQuery Mobile仅在Reports.php页面上使用,以便如果我在访问Reports.php页面后转到另一个页面,则不使用jQuery Mobile.

这是我链接到jQuery Mobile的代码(我仅在Reports.php页面中链接到jQuery Mobile):

<head>
    <link rel="stylesheet" href="../css/jQuery.css">
    <link rel="stylesheet" href="../css/Main.css">
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>

jQuery.css只是jQuery CSS的修改版本,因此不会干扰我的CSS,而Main.css是我的CSS.

解决方案

我假设您没有使用mod_rewrite,并且您的文件report.php在URL上可见.

根据您的评论:这是$ _SERVER ["REQUEST_URI"]的输出:

string(47) "/~a7068104/2013-2014/Lab_13/Reports/Reports.php"

因此,我们将使用stripos()检查用户是否正在请求其中包含"reports.php"的页面!我们使用的是不区分大小写的函数,而不是strpos(),您可以在( http://www.php.net/manual/zh/function.stripos.php )

您可以使用以下条件/逻辑:

<?php if ( stripos($_SERVER['REQUEST_URI'], "reports.php") ) : ?>

    <!-- add the html specific to the REPORTS.PHP -->


<?php else: ?>

    <!-- add the html specific to NON REPORTS.PHP Pages -->

<?php endif; ?>

<!-- Remember, everything else GOES OUTSIDE THE PHP IF CLAUSE --->

您的问题的解决方案是:

    <link rel="stylesheet" href="../css/jQuery.css">
    <link rel="stylesheet" href="../css/Main.css">
    <?php if ( stripos($_SERVER['REQUEST_URI'], "reports.php") ) : ?>
    <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
    <?php else: ?>
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <?php endif; ?>

希望这会有所帮助!

In the website that I am creating I use jQuery Mobile, which granted I don't know much about, and I'm having a big problem. In my website I only link to jQuery Mobile on one page, and I only want to use jQuery Mobile on one page (I don't know if that is possible, but that is what I want to do).

I have four main pages on my website: Homepage.php, SalesForms.php, Reports.php, and Login.php. I only want to use jQuery Mobile on the Reports.php page (I'm using it for its transitions to create a nice looking html form process).

Whenever I go to the Reports.php page it uses jQuery Mobile and jQuery and the jQuery Mobile CSS, which is good. But when I leave the Reports.php page and go to other pages, jQuery Mobile and its CSS is still being used, even when it isn't linked to on those page and when I don't want it to be used.

For example, when I visit Homepage.php it isn't using jQuery Mobile or its CSS, then I visit Reports.php which does use jQuery Mobile and its CSS, and then I visit Homepage.php again and it is still using jQuery Mobile and its CSS. This is a problem for me because jQuery Mobile's CSS is interfering with my CSS on pages other than the Reports.php page, which is the only page it is linked to on.

I want to know if and how I can make jQuery Mobile only be used on the Reports.php page so that if I go to another page after visiting the Reports.php page it doesn't use jQuery Mobile.

Here is my code where I link to jQuery Mobile (I only link to jQuery Mobile in my Reports.php page):

<head>
    <link rel="stylesheet" href="../css/jQuery.css">
    <link rel="stylesheet" href="../css/Main.css">
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>

jQuery.css is just a modified version of jQuery's CSS so that it doesn't interfere with my CSS and Main.css is my CSS.

解决方案

I'm assuming you're not using mod_rewrite and your file reports.php is visible on the url.

Based on your comment: This is the output for $_SERVER["REQUEST_URI"]:

string(47) "/~a7068104/2013-2014/Lab_13/Reports/Reports.php"

So, we're going to use stripos() to check if the user is requesting a page, that has "reports.php" in it! We are using the case insensitive function instead of strpos(), you can find more info at ( http://www.php.net/manual/en/function.stripos.php )

You can use the following condition / logic:

<?php if ( stripos($_SERVER['REQUEST_URI'], "reports.php") ) : ?>

    <!-- add the html specific to the REPORTS.PHP -->


<?php else: ?>

    <!-- add the html specific to NON REPORTS.PHP Pages -->

<?php endif; ?>

<!-- Remember, everything else GOES OUTSIDE THE PHP IF CLAUSE --->

The solution for your problem is:

    <link rel="stylesheet" href="../css/jQuery.css">
    <link rel="stylesheet" href="../css/Main.css">
    <?php if ( stripos($_SERVER['REQUEST_URI'], "reports.php") ) : ?>
    <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
    <?php else: ?>
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <?php endif; ?>

Hope this helps!

这篇关于如何使jQuery Mobile仅影响一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆