如何使jQuery移动版只影响一个页面

如何使jQuery移动版只影响一个页面,jquery,jquery-mobile,webpage,Jquery,Jquery Mobile,Webpage,在我创建的网站中,我使用jQuery Mobile,当然我对它了解不多,但我遇到了一个大问题。在我的网站上,我只在一个页面上链接到jQuery Mobile,我只想在一个页面上使用jQuery Mobile(我不知道这是否可行,但这正是我想要做的) 我的网站上有四个主要页面:Homepage.php、SalesForms.php、Reports.php和Login.php。我只想在Reports.php页面上使用jquerymobile(我使用它进行转换以创建一个漂亮的html表单过程) 每当我

在我创建的网站中,我使用jQuery Mobile,当然我对它了解不多,但我遇到了一个大问题。在我的网站上,我只在一个页面上链接到jQuery Mobile,我只想在一个页面上使用jQuery Mobile(我不知道这是否可行,但这正是我想要做的)

我的网站上有四个主要页面:Homepage.php、SalesForms.php、Reports.php和Login.php。我只想在Reports.php页面上使用jquerymobile(我使用它进行转换以创建一个漂亮的html表单过程)

每当我进入Reports.php页面时,它都会使用jquerymobile和jQuery以及jquerymobilecss,这很好。但是,当我离开Reports.php页面并转到其他页面时,jQuery Mobile及其CSS仍然在使用,即使在这些页面上没有链接,并且我不想使用它时也是如此

例如,当我访问Homepage.php时,它没有使用jQuery Mobile或其CSS,然后我访问Reports.php,它确实使用jQuery Mobile及其CSS,然后我再次访问Homepage.php,它仍然使用jQuery Mobile及其CSS。这对我来说是个问题,因为jQuery Mobile的CSS干扰了我在Reports.php页面以外的其他页面上的CSS,Reports.php页面是它唯一链接到的页面

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

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



jQuery.css只是jQuery的css的一个修改版本,因此它不会干扰我的css,Main.css是我的css。

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

根据您的评论:这是$\u服务器[“请求\u URI”]的输出:

因此,我们将使用stripos()检查用户是否正在请求一个包含“reports.php”的页面!我们使用的是不区分大小写的函数,而不是strpos(),您可以在()找到更多信息

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

<?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; ?>


希望这有帮助

我没有使用mod_rewrite,但这不起作用。我只是想把它放在我的CSS和jQuery链接的地方,对吗?是的,如果请求URI上有“reports.php”,它应该只显示php if子句中包装的html。该页面的url是什么?好的,刚改为stripos(),不区分大小写。注意到你的请求可能是大写的。这肯定有用!是的,试试最后一个修正。它应该会起作用。让我知道!那也没用。谢谢你的尝试!
<?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; ?>