根据网址隐藏div [英] Hide div based on url

查看:108
本文介绍了根据网址隐藏div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这是另一个转发。我一直在试图找到一个解决方案,但没有任何工作,我已经尝试过。我正在使用一个博客,我有完整的HTML控制。我通常可以找到基本html的方法,但是对于Java或CSS,我是一个完整的newb。对不起,我什么也不知道。

Sorry if this is another repost. I have been attempting to find a solution but nothing works that I have tried. I am using a blog which I have full html control over. I can usually find my way around basic html but when it comes to Java or CSS I am a complete newb. Sorry, I know absolutely nothing.

既然这样,我有两个边栏div,我试图隐藏在一个特定的网址,以利用更多的空间用于内容iframe。这是我尝试使用的编码之一,似乎没有工作,或者我失去了一些东西。

Now that that is out of the way. I have two sidebar div's that I am trying to hide on one specific url to utilize more space for a content iframe. This is one of the coded I have tried to use which doesn't seem to work or I am missing something.

<!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01 Transitional // EN
http://www.w3.org/TR/html4/loose.dtd\">
< html>
< head>
< script language =text / javascript
<?php
&#36;(function(){
if(window.location.search === mywebsite / Videos.html){
&#36;('#navleft')。hide();
} else {
&#36;('#navleft' ).show();
}
});
?>
< / script>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script language="text/javascript" <?php &#36;(function(){ if (window.location.search === "mywebsite/Videos.html") { &#36;('#navleft').hide(); } else { &#36;('#navleft').show(); } }); ?> </script>

请记住,当涉及到php或java时,我什么都不知道。我想为#navright和#navleft这样做。这也在CSS部分。感谢您的帮助!!

Please remember I do not know anything when it comes to php or java. I want to do this for both #navright and #navleft. Also this is in the CSS section. Thanks for any help!!

#navright{ width: 200px; }
#navleft{ width: 200px; }
#content{ margin:0px; }


推荐答案

看起来你正在使用jQuery,你需要包括浏览器的jQuery javascript文件来理解语法。

It looks like you are using jQuery, you need to include the jQuery javascript file for the browser to understand the syntax.

http://docs.jquery.com/Downloading_jQuery

另外,删除<?php ?> 标记并将&#36; 更改为 $

Also, remove the <?php and ?> tags and change &#36; to $:

如果您尝试获取当前网址, window.location.search 应改为 window.location.pathname

And if you are trying to get the current URL, window.location.search should be changed to window.location.pathname

https://developer.mozilla.org/zh/DOM/window.location

<script language="text/javascript">
$(function(){
      if (window.location.pathname == "mywebsite/Videos.html") {
            $('#navleft').hide();
      } else {
            $('#navleft').show();
      }
 });
</script>

这篇关于根据网址隐藏div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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