[英]Hide div when URL contains
I want to hide the slider (and a bit more) if someone uses the search module on my Joomla site and tried several solutions mentioned here on stackoverflow like: https://stackoverflow.com/a/1760605/1641903 如果有人在我的Joomla网站上使用搜索模块并尝试了在stackoverflow上提到的几种解决方案,例如: https : //stackoverflow.com/a/1760605/1641903,我想隐藏滑块(还有更多)
Currently my code looks like this: 目前,我的代码如下所示:
<script>
if (/\/search\//.test(window.location)) {
$('#hideonsearch').hide();
}
</script>
I wrapped the slider in <div id="hideonsearch>
and tried mentioned jquery in both the body and head (just to be sure), but it doesn't seem to work as you guys can see here . 我将滑块包裹在
<div id="hideonsearch>
并尝试在身体和头部都提到了jquery(请确保),但是似乎无法正常工作,正如你们在这里看到的那样。
Any idea on how to get in working? 对如何开始工作有任何想法吗?
I saw in your web site that the jquery is not loaded when your code is being executed. 我在您的网站上看到执行代码时未加载jquery。
You must put your code in the "onload" function, or make sure the jquery is loaded before doing this. 您必须将代码放入“ onload”函数中,或在执行此操作之前确保jquery已加载。
window.onload = function () {
if (/\/search\//.test(window.location)) {
jQuery('#hideonsearch').hide();
}
};
Or you can use the pure javascript code that is better. 或者,您可以使用更好的纯JavaScript代码。
window.onload = function () {
if (/\/search\//.test(window.location)) {
document.getElementById("hideonsearch").style.display = "none";
}
};
I saw another error in your web site now, related to this code: 我现在在您的网站上看到了另一个与此代码有关的错误:
jQuery(document).ready(function(){
jQuery('.hasTooltip').tooltip({"html": true,"container": "body"});
});
error: 错误:
undefined is not a function
未定义不是函数
And it is related to the same problem, jQuery is not loaded, so you can use "window.onload". 它与相同的问题有关,jQuery未加载,因此您可以使用“ window.onload”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.