编辑3 - 我们在其中发现我真的不是很聪明如果else语句显示为两个字符串:
假报警的人,我不能在我的当前设置使用PHP。我会在墙壁上撞击我的头一阵子。无论如何感谢您的帮助和建议。
我试图跟随this教程为了让“移动/全”在我的回应式网站开关。然而,用于显示选项的链接是同时显示的,而不是像它应该的那样的“任一或”情况。
本教程使用了一点PHP,我还不知道,所以我不知道错误的确切位置。这一切看起来好像没什么问题,但是这个代码:
<div id="toggleView">
<?php if ($fixedwidth == '1'): ?>
<a href="<?php echo $_SERVER["SCRIPT_NAME"] ?>?fixedwidth=0">Switch to Mobile site</a>
<?php else: ?>
<a href="<?php echo $_SERVER["SCRIPT_NAME"] ?>?fixedwidth=1">Switch to Full site</a>
<?php endif; ?>
</div>
应该只显示字符串中的一个,而是它会显示这样既链接:
?fixedwidth=0">Switch to Mobile site ?fixedwidth=1">Switch to Full site
我想这是一个语法问题与["Script_Name"]
段,但我不知道什么是正确的语法应该是。
编辑
这是我插入我的网页上,以检测fixedwidth
的变化PHP:
<?php
$fixedwidth = '';
// Check if the query string contains our key and assign its value to $fixedwidth
if (isset($_GET['fixedwidth']) && ($_GET['fixedwidth'] != "")) {
$fixedwidth = $_GET['fixedwidth'];
}
// Check if a cookie has already been set
if (isset($_COOKIE['fixedwidth'])) {
if ($fixedwidth == '0') {
// If the value is '0', delete the cookie
setcookie('fixedwidth', '', time() - 60, '/');
} else {
// Value is not '0', so no need to get the cookie value
$fixedwidth = '1';
}
} else if ($fixedwidth == '1') {
// The user wants fixed width, so set a cookie
$expires = 60 * 60 * 24 * 60 + time();
setcookie('fixedwidth', '1', $expires, '/');
}
?>
所以,我基本上是从教程复制粘贴此尝试在我的页面上获得此功能,但我不知道它是否真的正确。
编辑2 - 电动布加洛舞
下面是从页有问题的代码:
<%@ Master Language="c#" CodeFile="Standard.master.cs" Inherits="Standard_" %>
<%@ Register Src="/include/menu_left.ascx" TagName="menu_left" TagPrefix="uc4" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<?php
$fixedwidth = '1';
// Check if the query string contains our key and assign its value to $fixedwidth
if (isset($_GET['fixedwidth']) && ($_GET['fixedwidth'] != "")) {
$fixedwidth = $_GET['fixedwidth'];
}
// Check if a cookie has already been set
if (isset($_COOKIE['fixedwidth'])) {
if ($fixedwidth == '0') {
// If the value is '0', delete the cookie
setcookie('fixedwidth', '', time() - 60, '/');
} else {
// Value is not '0', so no need to get the cookie value
$fixedwidth = '1';
}
} else if ($fixedwidth == '1') {
// The user wants fixed width, so set a cookie
$expires = 60 * 60 * 24 * 60 + time();
setcookie('fixedwidth', '1', $expires, '/');
}
?>
<!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 id="Head1" runat="server">
<title>Website Title</title>
<asp:ContentPlaceHolder ID="MetaDescriptionHolder" runat="server" Visible="true">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="MetaKeywordsHolder" runat="server" Visible="true">
</asp:ContentPlaceHolder>
<meta name="author" content="website" />
<?php
// Only insert the meta[name="viewport"] element if responsive is not disabled
if ($fixedwidth = '1'): ?>
<meta name="viewport" content="width=1400, initial-scale=1" />
<?php endif; ?>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" type="text/css" href="fontawesome/css/font-awesome.min.css">
<link href="favicon.ico" rel="shortcut icon" />
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700' rel='stylesheet' type='text/css'>
<style type="text/css"><!-- @import url("../../../css/responsive.css?t=<%= DateTime.Now.Ticks %>"); --></style>
<%--<style type="text/css"><!-- @import url("../../../css/main-cs.css?t=<%= DateTime.Now.Ticks %>"); --></style>--%>
<script language="javascript" type="text/javascript" src="../../../js/jquery1.4.2.js"></script>
<script language="javascript" type="text/javascript" src="../../../js/validation.js"></script>
<script language="javascript" type="text/javascript" src="../../../js/functions.js"></script>
<script language="javascript" type="text/javascript" src="/js/browser-selector.js"></script>
<script src="/js/jquery.autocomplete.js" type="text/javascript"></script>
<asp:ContentPlaceHolder ID="slideshowHolder" runat="server" Visible="true">
</asp:ContentPlaceHolder>
<script type="text/javascript">
$(document).ready(function() {
$("#<%=txtSearch.ClientID %>").autocomplete('/SearchTextBox.ashx');
});
</script>
<script type="text/javascript">
function displayLogin(obj) {
if (obj.checked) {
if (!confirm('If you tick this box then you will no longer need to log in when visiting website from this computer.\n\nYou can disable this feature at any time by logging out.\n\nDon\'t use this option unless you are the only person who has access to this computer.\n\nWARNING:\nIf you do decide to use this option you will be liable for the actions of anyone who uses your login to access website.'))
{ obj.checked = false; }
}
}
var mouse_is_inside = false;
$(document).ready(function() {
$('#login_box').hover(function() {
mouse_is_inside = true;
}, function() {
mouse_is_inside = true;
});
});
</script>
</head>
<body>
<form id="Form1" runat="server">
<div class="top-menu">
<div class="top-menu-holder">
<div class="top-menu-tabs">
<div class="top-menu-tabs-shop-on">
<a href="/"><strong>Online Store</strong></a>
</div>
<div class="top-menu-tabs-residential">
<a href="http://www. <strong>IT Services</strong></a>
</div>
<div class="top-menu-tabs-services">
<a href="link">Business <strong>IT Services</strong></a>
</div>
</div>
<div class="top-menu-menu">
<ul>
<li class="line"><a href="/contact-us.aspx" alt="Contact Us" title="Contact Us">Contact</a></li>
<li class="line"><a href="/about-us.aspx" alt="About Us" title="About Us">About</a></li>
<li class="line"><a href="/feedback.aspx" alt="Feedback" title="Feedback">Feedback</a></li>
<li class="line"><a href="/testimonials.aspx" alt="Testimonials" title="Testimonials">
Testimonials</a></li>
<li class="line"><a href="/employment.aspx" alt="Employment" title="Employment">Employment</a></li>
<li class="line"><a href="/awards.aspx" alt="Awards" title="Awards">Awards</a></li>
<li class="line"><a href="/Gift-Vouchers/Gift-Vouchers/Index.aspx" alt="Gift Vouchers" title="Gift Vouchers">Vouchers</a></li>
<li class="line"><a href="/promotions.aspx" alt="Promotions" title="Promotions">Promotions</a></li>
</ul>
</div>
</div>
</div>
<div class="page-content">
<div class="shop-header">
<div class="shop-header-logo">
<a href="/">
<img alt="Online Store" src="/images/shop-logo.png" /></a>
</div>
<div class="shop-header-phone">
Freephone<br />
</div>
<div class="shop-header-ad" style='<%# "display:" + (c.CustomerID >0 || Convert.ToInt32(c.GetTotalsForCart()[0]) > 0 ? "none": "") %>'>
<a href="https://shop.eset.co.nz/shop/?mode=tr&resellerid=IyUqXygK">
<img alt="eset free 30 day trial" src="/images/top-strip-ad/eset-trial.jpg" title="eset free 30 day trial" /></a>
</div>
<asp:Panel ID="pnlCart" runat="server">
<div class="shop-header-cart">
<div class="shop-header-cart-label-cart">
Shopping Cart:</div>
<div class="shop-header-cart-label-link">
<a id="A12" class="white" href="~/cart.aspx" runat="server">Shopping Cart:</a></div>
<div class="shop-header-cart-label">
Items:</div>
<div class="shop-header-cart-details">
<asp:Label ID="lblProducts" runat="server"></asp:Label></div>
<div class="shop-header-cart-label">
Total:</div>
<div class="shop-header-cart-details">
$<asp:Label ID="lblCost" runat="server"></asp:Label></div>
<div class="shop-header-cart-button">
<div class="green-button">
<a id="A6" href="~/cart.aspx" runat="server">View Cart</a>
</div>
</div>
</div>
</asp:Panel>
<asp:Panel ID="pnlAccount" runat="server" Visible="false">
<div class="account-menu">
<ul>
<li><a id="A2" href="~/saved-carts.aspx" runat="server">Saved Carts</a></li>
<li id="lstAccountModule1" runat="server" visible="false" class="line"><a id="A3"
href="~/transactions.aspx" runat="server">Transactions</a></li>
<li id="lstAccountModule2" runat="server" visible="false" class="line"><a id="A4"
href="~/orders.aspx" runat="server">Orders</a></li>
<li id="lstServiceModule1" runat="server" visible="false" class="line"><a id="A5"
href="~/service-tickets.aspx" runat="server">Service Tickets</a></li>
<li id="lstManageModule" runat="server" visible="false" class="line"><a id="A7"
href="~/manage.aspx" runat="server">Manage</a></li>
</ul>
</div>
</asp:Panel>
</div>
<div class="shop-menu-login-bar">
<asp:Panel ID="pnlLoggedOut" runat="server" autocomplete="off">
<ul>
<li>
<a href="/log-in.aspx" alt="Log In" title="Log In">Log In</a>
</li>
<li class="line">
<a href="/create-account.aspx" alt="Register" title="Register">Register</a>
</li>
</ul>
</asp:Panel>
<asp:Panel ID="pnlLoggedIn" runat="server" autocomplete="off">
<ul>
<li>
<a href="~/log-in.aspx?logout=1" id="A8" runat="server">Logout</a>
</li>
<li class="line">
<a id="A9" href="~/update-details.aspx" runat="server">My Details</a>
</li>
</ul>
</asp:Panel>
<asp:Panel ID="pnlsearch3" runat="server" DefaultButton="btnsearch3">
<div class="search-3">
<asp:TextBox ID="txtSearch3" runat="server" Class="search-textbox-3" onblur="if(this.value == '') { this.value='Enter keyword or product code'; isSet=true; }"
onmouseover="if(this.value == 'Enter keyword or product code') { this.value='';isSet = true; }"
onmouseout="if(this.value == '' && !isSet) { this.value='Enter keyword or product code'; isSet=>false; }"
MaxLength="255" Text="Enter keyword or product code" ontextchanged="btnsearch3_Click" />
<asp:ImageButton ID="btnsearch3" Class="search-icon-3" ImageAlign="Right" BackColor="White" runat="server" Width="20" Height="20" OnClick="btnsearch3_Click" ImageUrl="~/images/search-icon.gif" />
</div>
</asp:Panel>
</div>
<div class="shop-menu">
<div class="shop-menu-float-left">
<ul>
<li><asp:HyperLink runat="server" ID="hlComputers" NavigateUrl="/Computers/Index.aspx" Text="Computers" ToolTip="View Products in Computers Category"/></li>
<li class="line"><asp:HyperLink ID="hlElectronics" NavigateUrl="/Electronics/Index.aspx" runat="server" tooltip="View Products in Electronics Category" Text="Electronics"/></li>
<li class="line"><asp:HyperLink ID="hlExLease" NavigateUrl="/Computers/Ex-Lease/index.aspx" runat="server" tooltip="View our Ex-Lease Items" Text="Ex-Lease"/></li>
<li class="line"><asp:HyperLink ID="hlClearance" NavigateUrl="/search.aspx?S=Clearance+Item&picture=0" runat="server" tooltip="View our Clearence Items" Text="Clearance"/></li>
<li class="line"><asp:HyperLink ID="hlRepairs" NavigateUrl="/Christchurch-Computer-Repairs-and-Service.aspx" runat="server" tooltip="View our Store Service Department" Text="Repairs" /></li>
</ul>
</div>
<div class="shop-menu-float-right">
<asp:Panel ID="pnlLogin" runat="server" autocomplete="off">
<div class="green-button">
<a href="#" alt="Log In" title="Log In" onclick="$('#login_box').fadeIn("fast"); mouse_is_inside = true; if(frmvalidator != null) { DisableAllValidators();}; return false;">Log In</a>
</div>
<div class="my-details">
<div class="green-button">
<a href="/create-account.aspx" alt="Register" title="Register">Register</a>
</div>
</div>
<div id="login_box">
<div id="login_box_content">
<div class="login-row">
<h2 class="login">
Login<a onclick="javascript:$('#login_box').fadeOut("fast");"><img alt=''
src="/images/close.png" class="login-close" /></a></h2>
</div>
<div class="login-row">
<div class="login-label">
Email</div>
<div class="login-field">
<input type="text" id="txtLoginEmail" autocomplete="off" name="txtLoginEmail" tabindex="1" maxlength="255"
class="login-input" /></div>
</div>
<div class="login-row">
<div class="login-label">
Password</div>
<div class="login-field">
<input type="password" name="txtLoginPassword" autocomplete="off" id="txtLoginPassword" tabindex="2"
maxlength="255" class="login-input" />
</div>
</div>
<div class="login-remember">
<div class="login-remember-field">
<input name="auto_login" id="auto_login" onclick="displayLogin(this);" tabindex="3" type="checkbox" />
</div>
<div class="login-remember-label">
Remember Me
</div>
</div>
<div class="login-button">
<div class="green-button">
<input type="image" causesvalidation="false" src="/images/log-in.png" alt="login" title="login" tabindex="4" runat="server" id="login" />
</div>
</div>
<div class="login-remember">
<a href="/forgotten-password.aspx">Forgot your password?</a>
</div>
</div>
</div>
<input type="hidden" name="previousPage" value="<%=strPreviousPage %>" />
</asp:Panel>
<asp:Panel ID="pnlLogoutMenu" runat="server">
<div class="green-button">
<a href="~/log-in.aspx?logout=1" id="logout" runat="server">Logout</a>
</div>
<div class="my-details">
<div class="green-button">
<a id="A1" href="~/update-details.aspx" runat="server">My Details</a>
</div>
</div>
</asp:Panel>
<asp:Panel ID="pnlSearch" runat="server" DefaultButton="ImageButton1">
<div class="search-textbox">
<asp:TextBox ID="txtSearch" runat="server" CssClass="search" onblur="if(this.value == '') { this.value='Enter keyword or product code'; isSet=true; }"
onmouseover="if(this.value == 'Enter keyword or product code') { this.value='';isSet = true; }"
onmouseout="if(this.value == '' && !isSet) { this.value='Enter keyword or product code'; isSet=>false; }"
MaxLength="255" Text="Enter keyword or product code" ontextchanged="btnSearch_Click" /><asp:ImageButton ID="ImageButton1" Class="search-icon" ImageAlign="Right" Width="15" Height="15" BackColor="White" runat="server" OnClick="btnSearch_Click" ImageUrl="~/images/search-icon.gif" />
</div>
</asp:Panel>
</div>
<input type="hidden" name="previousPage" value="<%=strPreviousPage %>"
</div>
<asp:Panel ID="pnlmsearch" runat="server" DefaultButton="btnmsearch" Visible="true">
<div class="search-m">
<asp:TextBox ID="txtSearchM" runat="server" Class="search-textbox-m" onblur="if(this.value == '') { this.value='Enter keyword or product code'; isSet=true; }"
onmouseover="if(this.value == 'Enter keyword or product code') { this.value='';isSet = true; }"
onmouseout="if(this.value == '' && !isSet) { this.value='Enter keyword or product code'; isSet=>false; }"
MaxLength="255" Text="Enter keyword or product code" ontextchanged="btnmsearch_Click" />
<asp:ImageButton ID="btnmsearch" Class="search-icon-m" ImageAlign="Right" BackColor="White" runat="server" Width="30" Height="30" OnClick="btnmsearch_Click" ImageUrl="~/images/search-icon.gif" />
</div>
</asp:Panel>
<div class="content-holder">
<div class="page-content-menu">
<uc4:menu_left ID="Menu_left" runat="server" />
</div>
<div class="page-content-info">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
<div class="footer">
<div id="toggleView">
<?php if ($fixedwidth == '1') { ?>
<a href="<?php echo $_SERVER["SCRIPT_NAME"] ?>?fixedwidth=0">Switch to Mobile site</a>
<?php } else { ?>
<a href="<?php echo $_SERVER["SCRIPT_NAME"] ?>?fixedwidth=1">Switch to Full site</a>
<?php } ?>
</div>
<div class="footer-content">
<div class="footer-content-border">
<div class="footer-payment-method">
<div class="footer-payment-method-border">
<div class="footer-payment-text">
Secure online payments with <strong>3D Secure</strong></div>
<div class="footer-payment-visa-verified">
<img runat="server" src="/images/verified-by-visa.png" alt="Verified by Visa" title="Verified by Visa" /></div>
<div class="footer-payment-mastercard-securecode">
<img runat="server" src="/images/mastercard-securecode.png" alt="MasterCard SecureCode" title="MasterCard SecureCode" /></div>
<div class="footer-payment-visa">
<img runat="server" src="/images/visa-logo.png" alt="site accepts Visa" title=site accepts Visa" /></div>
<div class="footer-payment-mastercard">
<img runat="server" src="/images/mastercard-logo.png" alt="Global PC accepts Mastercard"
title="site accepts Mastercard" /></div>
<div class="footer-payment-payment-express">
<img runat="server" src="/images/payment-express.png" alt=" accepts Payment Express"
title=" PC accepts Payment Express" /></div>
</div>
</div>
<div class="footer-social-media">
<div class="footer-title">
Social Media</div>
<div class="footer-facebook">
<a runat="server" href="http://www.facebook.com/" target="_blank">
<img runat="server" src="/images/facebook.png" border="0" alt="Become a fan of on Facebook"
title="Become a fan of on Facebook" /></a>
</div>
</div>
<div class="footer-links-left">
<div class="footer-title">
Shopping</div>
<a href="/">Home</a><br />
<a href="/cart.aspx">View cart</a><br />
<a href="/promotions.aspx">Promotions</a><br />
<a href="/create-account.aspx">Create Account</a>
</div>
<div class="footer-links-right">
<div class="footer-title">
About </div>
<a href="/contact-us.aspx">Contact us</a><br />
<a href="/about-us.aspx">About us</a><br />
<a href="/contact-us.aspx">Stores</a><br />
<a href="/suppliers.aspx">Suppliers</a><br />
<a href="/feedback.aspx">Feedback</a>
</div>
<div class="footer-legal">
<div class="footer-title">
Legal Information</div>
<a href="/terms.aspx">Terms and Conditions</a><br />
<a href="/privacy.aspx">Privacy policy</a><br />
<asp:Label ID="lblCopyright" runat="server"></asp:Label>
</div>
</div>
</div>
</div>
</div>
</form>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-8649565-1");
pageTracker._trackPageview();
} catch (err) { }</script>
</body>
</html>
[不能重现。](https://ideone.com/95bx5K) – Zsw
其实@Zsw你**可以**,这正是应该发生的! :) IDK,如果它是OP想要的,那么... –
所以这是一个问题'固定宽度'设置的方式? – Wompguinea