JavaScript:显示/隐藏< DIV>基于URL字符串 [英] JavaScript: Show / Hide <DIV> based on URL string
本文介绍了JavaScript:显示/隐藏< DIV>基于URL字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在两个页面(URL)上显示DIV,而不是在其他页面上显示。
(如果有帮助,我在页面上有jQuery。)。我是一个完整的菜鸟,所以所有的帮助都非常感激。谢谢!
I need to show a DIV on two pages (URL's) but not on the others. (I have jQuery on the pages if that helps.). I'm a complete noob so all help is very much appreciate. Thank's!
案例(1)我要展示DIV:
- 在开始页面上,当Web浏览器地址字段显示为www.mydomin.com时
- 起始页是PHP,所以我想完整的URL是'www.mydomin.com/index.php'
案例(2):
- 'www.mydomin.com/index.php?option=com_myblog&title.html&Itemid=1&lang=en'
- 此部分始终相同
- 'www.mydomin.com/index.php?option=com_myblog&'
- 此部分始终是唯一的
- 'title.html& Itemid = 1& lang = en
- 'www.mydomin.com/index.php?option=com_myblog&title.html&Itemid=1&lang=en'
- WHERE this part is alway the same
- 'www.mydomin.com/index.php?option=com_myblog&'
- AND this part is always unique
- 'title.html&Itemid=1&lang=en
示例
if (url == 'www.mydomin.com' or 'www.mydomin.com/index.php?option=com_myblog&') {
do this
xxxxxxxx
else
nothing
推荐答案
如果我理解正确的问题,这应该有用
This should work, if I understand the question correctly
var url = document.location.href;
if (url.indexOf('www.mydomin.com/index.php?option=com_myblog&') >= 0) {
$('#div_id').hide();
} else {
$('#div_id').show();
}
但实际上,如果你使用PHP,你应该弄清楚如何不首先渲染div。
But really, if you use PHP anyway, you should figure out how to not render the div in the first place.
这篇关于JavaScript:显示/隐藏< DIV>基于URL字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文