Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基于多个URL隐藏/显示内容_Javascript_Php_Jquery_Css - Fatal编程技术网

Javascript 基于多个URL隐藏/显示内容

Javascript 基于多个URL隐藏/显示内容,javascript,php,jquery,css,Javascript,Php,Jquery,Css,想知道是否有可能隐藏或显示基于多个URL的内容 例如,用户在家中或使用www.url.com/或www.url.com/index.html索引 特定元素显示:块或显示:无 if(location=="http://domain.com/") { 很好,但是如何以上述相同的类似格式指定多个URL呢?通过测试位置。路径名如下: document.getElementById('specific').style.display = location.pathname === "/index.h

想知道是否有可能隐藏或显示基于多个URL的内容

例如,用户在家中或使用www.url.com/或www.url.com/index.html索引

特定元素
显示:块
显示:无

  if(location=="http://domain.com/") {

很好,但是如何以上述相同的类似格式指定多个URL呢?

通过测试
位置。路径名
如下:

document.getElementById('specific').style.display = location.pathname === "/index.html" ? 'none' : 'block';

您可以使用sammy.js()。它有一个很好的URL路由功能。

您可以使用PHP获取URL信息。假设您有以下URL:

https://www.wherever.com/some_file.php?css1=1&css2=1
另一方面,假设URL看起来像:

https://www.wherever.com/some_file.php?css3=1&css4=1
编写生成HTML的PHP页面时:

<?php
$css = '';
function link_builder(){
  $a = func_get_args(); $lo = "<link rel='stylesheet' type='text/css' href='"; $lc = "' />"; $o = '';
  foreach($a as $v){
    $o .= "$lo$v$lc";
  }
  return $o;
}
if(isset($_GET['css1'], $_GET['css2']) && $_GET['css1'] === '1' && $_GET['css2'] === '1'){
  $css = link_builder('cssPath1.css', 'cssPath2.css');
}
if(isset($_GET['css3'], $_GET['css4']) && $_GET['css3'] === '1' && $_GET['css4'] === '1'){
  $css = link_builder('cssPath3.css', 'cssPath4.css');
}
echo $css;
?>


使用这种方法,您可以提前创建单独的外部CSS文件,这些文件可以缓存到客户端的浏览器内存中。JavaScript样式不会这样做。

谢谢!不知道为什么我被否决了,只是从来没有遇到过尝试这种技术的问题。谢谢你
<?php
$css = '';
function link_builder(){
  $a = func_get_args(); $lo = "<link rel='stylesheet' type='text/css' href='"; $lc = "' />"; $o = '';
  foreach($a as $v){
    $o .= "$lo$v$lc";
  }
  return $o;
}
if(isset($_GET['css1'], $_GET['css2']) && $_GET['css1'] === '1' && $_GET['css2'] === '1'){
  $css = link_builder('cssPath1.css', 'cssPath2.css');
}
if(isset($_GET['css3'], $_GET['css4']) && $_GET['css3'] === '1' && $_GET['css4'] === '1'){
  $css = link_builder('cssPath3.css', 'cssPath4.css');
}
echo $css;
?>