简体   繁体   English

URL包含时隐藏div

[英]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”。

隐藏父 div 时包含<textarea>&lt;i&gt;?&lt;/div&gt;&lt;/i&gt; &lt;b&gt;?&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我有一个由其内容动态生成的 div 结构。 它看起来像这样:</p><pre> &lt;div class="fpd-list-row fpd-add-layer" id="1609962837979"&gt;&lt;div class="fpd-cell-0"&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="fpd-cell-1"&gt;Dein Foto&lt;/div&gt;&lt;div class="fpd-cell-2"&gt;&lt;span class="fpd-icon-add"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="fpd-list-row" id="1609962838288"&gt;&lt;div class="fpd-cell-0"&gt;&lt;span class="fpd-current-color" style="background: #ffffff" data-colors=""&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="fpd-cell-1"&gt;&lt;textarea&gt;Wanderlust&lt;/textarea&gt;&lt;/div&gt;&lt;div class="fpd-cell-2"&gt;&lt;span class="fpd-lock-element"&gt;&lt;span class="fpd-icon-unlocked"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</pre><p> 我只想隐藏 textareas 和 parent 元素到 .fpd-list-row 但保持其他 div like.fpd-list-row.fpd-add-layer 不变。 当我将 textarea 设置为不显示时,父 div 仍然存在。 有没有办法仅在包含&lt;textarea&gt;时将父 div 隐藏到 ..fpd-list-row ?</p></div> - Hide parent div when it contains <textarea>?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果URL包含单词,则隐藏div - Hide div if URL contains word URL包含特定文本部分时显示或隐藏div - Show or hide div when URL contains certain section of text 如果网址包含字词,则在iframe中隐藏div - Hide div in iframe if URL contains word 隐藏父 div 时包含<textarea>&lt;i&gt;?&lt;/div&gt;&lt;/i&gt; &lt;b&gt;?&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我有一个由其内容动态生成的 div 结构。 它看起来像这样:</p><pre> &lt;div class="fpd-list-row fpd-add-layer" id="1609962837979"&gt;&lt;div class="fpd-cell-0"&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="fpd-cell-1"&gt;Dein Foto&lt;/div&gt;&lt;div class="fpd-cell-2"&gt;&lt;span class="fpd-icon-add"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="fpd-list-row" id="1609962838288"&gt;&lt;div class="fpd-cell-0"&gt;&lt;span class="fpd-current-color" style="background: #ffffff" data-colors=""&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="fpd-cell-1"&gt;&lt;textarea&gt;Wanderlust&lt;/textarea&gt;&lt;/div&gt;&lt;div class="fpd-cell-2"&gt;&lt;span class="fpd-lock-element"&gt;&lt;span class="fpd-icon-unlocked"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</pre><p> 我只想隐藏 textareas 和 parent 元素到 .fpd-list-row 但保持其他 div like.fpd-list-row.fpd-add-layer 不变。 当我将 textarea 设置为不显示时,父 div 仍然存在。 有没有办法仅在包含&lt;textarea&gt;时将父 div 隐藏到 ..fpd-list-row ?</p></div> - Hide parent div when it contains <textarea>? 如果不包含,则隐藏另一个div - Hide another div if not contains 当 URL 中不存在 searchParams 时隐藏 div - Hide div when searchParams are does not exist in URL 当锚文本包含特定关键字时隐藏父DIV - Hide the parent DIV when an Anchor Text contains a certain Keyword 当h4包含尾部文字时隐藏父DIV - Hide parent DIV when h4 contains certail text 当 url 包含某个参数时隐藏页眉/页脚 - Hide header/footer when url contains a certain parameter 当 URL 包含特定术语时显示/隐藏元素 - Show / Hide element when URL contains a specific term
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM