2015-10-07 104 views
1

我試圖隱藏基於字符串的元素在我的網站元標題。基於元標題的隱藏元素

這是腳本我嘗試:

if($('title:contains("hide if this text shows")')){ 
    $(".fusion-footer-widget-area .fusion-row").addClass("hide"); 
} 

該廣告的新類來我的元素,我已經設定display:none

不過。這隱藏我的元素,無論文字。我究竟做錯了什麼?

+0

添加有關HTML也 – Tushar

+0

相關的HTML?它只是我的頁腳元素。然後它的基本標籤出現在我的文本中。 – Xeptor

+1

'我的網站元標題.'這令人困惑,'',''或'<a title=''>' – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/2025923/">Tushar</a></span> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> </div> <div class="answer-title"> <span class="text-logo margin-top-sm">A</span> <h2 class="title h4">回答</h2> </div> <div class="item-description text-md markdown-body margin-bottom-40 voidso"> <article class="board-top-1 padding-top-10"> <div class="post-col vote-info"> <span class="count">5<i class="fa fa-thumbs-up"></i></span> <i class="fa fa-check fa-2x"></i> </div> <div class="post-offset"> <div class="answer fmt"> <p>使用<strong><a href="https://api.jquery.com/length/"><code class="prettyprint-override">length</code></a></strong>要檢查的屬性。因爲它是一個定義的對象<code class="prettyprint-override">$('title:contains("hide if this text shows")')</code>將永遠真實的,你應該使用<code class="prettyprint-override">$('title:contains("hide if this text shows")').length</code></p> <pre><code class="prettyprint-override">if($('title:contains("hide if this text shows")').length){ $(".fusion-footer-widget-area .fusion-row").addClass("hide"); } </code></pre> <p>或者使用<strong><a href="https://api.jquery.com/is/"><code class="prettyprint-override">is()</code></a></strong>返回如果選擇匹配</p> <pre><code class="prettyprint-override">if($('title').is(':contains("hide if this text shows")')){ $(".fusion-footer-widget-area .fusion-row").addClass("hide"); } </code></pre> </div> <div class="post-info"> <div class="post-meta row"> <p class="text-secondary col-lg-6"> <span class="source"> <a rel="noopener" target="_blank" href="https://stackoverflow.com/q/32985767">來源</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2015-10-07 07:03:48</span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> </div> </article> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1038284119" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="clearfix"> </div> <div class="relative-box"> <div class="relative">相關問題</div> <ul class="relative_list"> <li> 1. <a href="http://hk.uwenku.com/question/p-tdiendwl-vh.html" target="_blank" title="隱藏基於URL的元素href"> 隱藏基於URL的元素href </a> </li> <li> 2. <a href="http://hk.uwenku.com/question/p-wfcmmexv-md.html" target="_blank" title="基於URL的隱藏元素"> 基於URL的隱藏元素 </a> </li> <li> 3. <a href="http://hk.uwenku.com/question/p-vuzfdhtr-bbv.html" target="_blank" title="基於userAgent的iOS/Android隱藏元素"> 基於userAgent的iOS/Android隱藏元素 </a> </li> <li> 4. <a href="http://hk.uwenku.com/question/p-eytmrrba-bdz.html" target="_blank" title="基於ID的隱藏元素onClick React"> 基於ID的隱藏元素onClick React </a> </li> <li> 5. <a href="http://hk.uwenku.com/question/p-yzsvlzzp-vg.html" target="_blank" title="基於視圖隱藏/顯示元素"> 基於視圖隱藏/顯示元素 </a> </li> <li> 6. <a href="http://hk.uwenku.com/question/p-dzpfquxu-ek.html" target="_blank" title="基於過濾器隱藏元素"> 基於過濾器隱藏元素 </a> </li> <li> 7. <a href="http://hk.uwenku.com/question/p-nsfxctgu-bev.html" target="_blank" title="如何隱藏基於一系列父元素的HTML元素"> 如何隱藏基於一系列父元素的HTML元素 </a> </li> <li> 8. <a href="http://hk.uwenku.com/question/p-cshmzqso-bgq.html" target="_blank" title="使用基於子元素的alt標記的JS/JQuery隱藏父元素"> 使用基於子元素的alt標記的JS/JQuery隱藏父元素 </a> </li> <li> 9. <a href="http://hk.uwenku.com/question/p-scdrviey-mr.html" target="_blank" title="隱藏元素點擊隱藏元素"> 隱藏元素點擊隱藏元素 </a> </li> <li> 10. <a href="http://hk.uwenku.com/question/p-axtxushw-hw.html" target="_blank" title="訪問/隱藏標題元素"> 訪問/隱藏標題元素 </a> </li> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-6208739752673518" data-ad-slot="4606349252"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <li> 11. <a href="http://hk.uwenku.com/question/p-vphjdogl-ug.html" target="_blank" title="在IE8中隱藏標題元素"> 在IE8中隱藏標題元素 </a> </li> <li> 12. <a href="http://hk.uwenku.com/question/p-sagunaic-bas.html" target="_blank" title="隱藏標記元素"> 隱藏標記元素 </a> </li> <li> 13. <a href="http://hk.uwenku.com/question/p-fmwtmxhr-qy.html" target="_blank" title="隱藏元素"> 隱藏元素 </a> </li> <li> 14. <a href="http://hk.uwenku.com/question/p-rkabeiux-vz.html" target="_blank" title="隱藏元素"> 隱藏元素 </a> </li> <li> 15. <a href="http://hk.uwenku.com/question/p-wyldwzlp-bgn.html" target="_blank" title="隱藏元素"> 隱藏元素 </a> </li> <li> 16. <a href="http://hk.uwenku.com/question/p-sioxcwrg-uq.html" target="_blank" title="隱藏的元素?"> 隱藏的元素? </a> </li> <li> 17. <a href="http://hk.uwenku.com/question/p-kpnognmw-bdh.html" target="_blank" title="基於最後關閉的元素jQuery腳本的隱藏元素"> 基於最後關閉的元素jQuery腳本的隱藏元素 </a> </li> <li> 18. <a href="http://hk.uwenku.com/question/p-autgkkoj-de.html" target="_blank" title="僅隱藏父元素的子元素"> 僅隱藏父元素的子元素 </a> </li> <li> 19. <a href="http://hk.uwenku.com/question/p-grgijfgx-k.html" target="_blank" title="隱藏元素中的元素與類"> 隱藏元素中的元素與類 </a> </li> <li> 20. <a href="http://hk.uwenku.com/question/p-xdmmkriv-ng.html" target="_blank" title="。元素/隱藏元素的設置值"> 。元素/隱藏元素的設置值 </a> </li> <li> 21. <a href="http://hk.uwenku.com/question/p-wknnjlaq-ca.html" target="_blank" title="Mouseleave隱藏元素?"> Mouseleave隱藏元素? </a> </li> <li> 22. <a href="http://hk.uwenku.com/question/p-wzqdpqse-wr.html" target="_blank" title="UIWebView隱藏元素"> UIWebView隱藏元素 </a> </li> <li> 23. <a href="http://hk.uwenku.com/question/p-eaocjrbl-sv.html" target="_blank" title="隱藏p元素"> 隱藏p元素 </a> </li> <li> 24. <a href="http://hk.uwenku.com/question/p-bxlmerkh-bbo.html" target="_blank" title="隱藏html元素"> 隱藏html元素 </a> </li> <li> 25. <a href="http://hk.uwenku.com/question/p-pfnprftv-bkh.html" target="_blank" title="Android:隱藏元素"> Android:隱藏元素 </a> </li> <li> 26. <a href="http://hk.uwenku.com/question/p-fhqenxjo-de.html" target="_blank" title="爲何隱藏新元素附加到的舊元素時隱藏新元素?"> 爲何隱藏新元素附加到的舊元素時隱藏新元素? </a> </li> <li> 27. <a href="http://hk.uwenku.com/question/p-kbotjruk-ot.html" target="_blank" title="關於隱藏元素的jQuery CSS"> 關於隱藏元素的jQuery CSS </a> </li> <li> 28. <a href="http://hk.uwenku.com/question/p-qaqevcvx-bbw.html" target="_blank" title="Schema.org - 關於隱藏元素的數據"> Schema.org - 關於隱藏元素的數據 </a> </li> <li> 29. <a href="http://hk.uwenku.com/question/p-fbpvstlt-bmq.html" target="_blank" title="jQuery:隱藏的元素 - 一般問題"> jQuery:隱藏的元素 - 一般問題 </a> </li> <li> 30. <a href="http://hk.uwenku.com/question/p-pjyucqqp-vp.html" target="_blank" title="jQuery的問題與隱藏李元素"> jQuery的問題與隱藏李元素 </a> </li> </ul> </div> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1575177025"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="padding-top-10"></div> </div> </div> <script type="text/javascript" src="http://img.uwenku.com/uwenku/script/side.js?t=1644592048261"></script> <script type="text/javascript" src="http://img.uwenku.com/uwenku/plugin/highlight/highlight.pack.js"></script> <link href="http://img.uwenku.com/uwenku/plugin/highlight/styles/docco.css" media="screen" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $('pre').each(function(i, e) { hljs.highlightBlock(e, "<span class='indent'> </span>", false) }); </script> <div class="col-lg-3 col-md-4 col-sm-5"> <div id="rightTop"> <div class="row"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="5415218910" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="row sidebar panel panel-default"> <div class="panel-heading font-bold"> 最新問題 </div> <div class="m-b-sm m-t-sm clearfix"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-yqndqgqw-bgc.html" target="_blank" title="jquery循環條件"> jquery循環條件 </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-apzouooa-bev.html" target="_blank" title="爲什麼SQLAlchemy關聯對象中的外鍵標記爲主鍵?"> 爲什麼SQLAlchemy關聯對象中的外鍵標記爲主鍵? </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-navhsyjn-bgs.html" target="_blank" title="爲什麼我的禁用/啓用複選框在JQuery中不起作用?"> 爲什麼我的禁用/啓用複選框在JQuery中不起作用? </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-ujuawspd-bmt.html" target="_blank" title="將自定義表格行添加到PHP中的HTML表格中"> 將自定義表格行添加到PHP中的HTML表格中 </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-hletfehz-bmn.html" target="_blank" title="如何防止對php或mysql級別的雙表單提交?"> 如何防止對php或mysql級別的雙表單提交? </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-pxyajeqb-boc.html" target="_blank" title="PostgreSQL中的時間序列有很大的查詢需求"> PostgreSQL中的時間序列有很大的查詢需求 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-qdabqehu-bnq.html" target="_blank" title="如何模擬上下文(ActorContext)?"> 如何模擬上下文(ActorContext)? </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-kgedkfos-bnh.html" target="_blank" title="包括恢復提交的Rebase"> 包括恢復提交的Rebase </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-pweweabj-bdc.html" target="_blank" title="如何從存儲在郵件Laravel"> 如何從存儲在郵件Laravel </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-arjezbvg-bdn.html" target="_blank" title="閱讀Csv到namedtuple"> 閱讀Csv到namedtuple </a> </li> </ul> </div> </div> </div> <p class="article-nav-bar"></p> <div class="row sidebar article-nav"> <div class="row box_white visible-sm visible-md visible-lg margin-zero"> <div class="top"> <h3 class="title"><i class="glyphicon glyphicon-th-list"></i> 相關問題</h3> </div> <div class="article-relative-content"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-tdiendwl-vh.html" target="_blank" title="隱藏基於URL的元素href"> 隱藏基於URL的元素href </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-wfcmmexv-md.html" target="_blank" title="基於URL的隱藏元素"> 基於URL的隱藏元素 </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-vuzfdhtr-bbv.html" target="_blank" title="基於userAgent的iOS/Android隱藏元素"> 基於userAgent的iOS/Android隱藏元素 </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-eytmrrba-bdz.html" target="_blank" title="基於ID的隱藏元素onClick React"> 基於ID的隱藏元素onClick React </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-yzsvlzzp-vg.html" target="_blank" title="基於視圖隱藏/顯示元素"> 基於視圖隱藏/顯示元素 </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-dzpfquxu-ek.html" target="_blank" title="基於過濾器隱藏元素"> 基於過濾器隱藏元素 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-nsfxctgu-bev.html" target="_blank" title="如何隱藏基於一系列父元素的HTML元素"> 如何隱藏基於一系列父元素的HTML元素 </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-cshmzqso-bgq.html" target="_blank" title="使用基於子元素的alt標記的JS/JQuery隱藏父元素"> 使用基於子元素的alt標記的JS/JQuery隱藏父元素 </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-scdrviey-mr.html" target="_blank" title="隱藏元素點擊隱藏元素"> 隱藏元素點擊隱藏元素 </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-axtxushw-hw.html" target="_blank" title="訪問/隱藏標題元素"> 訪問/隱藏標題元素 </a> </li> </ul> </div> </div> </div> </div> </div> </div> </div><!-- wrap end--> <!-- footer --> <footer id="footer"> <div class="bg-simple lt"> <div class="container"> <div class="row padder-v m-t"> <div class="col-xs-8"> <ul class="list-inline"> <li><a href="http://hk.uwenku.com/contact">聯系我們</a></li> <li>© 2020 HK.UWENKU.COM</li> <li><a target="_blank" href="https://beian.miit.gov.cn/">沪ICP备13005482号-4</a></li> <li><script type="text/javascript" src="https://v1.cnzz.com/z_stat.php?id=1280101193&web_id=1280101193"></script></li> <li><a href="http://www.uwenku.com/" target="_blank" title="优文库">简体中文</a></li> <li><a href="http://hk.uwenku.com/" target="_blank" title="優文庫">繁體中文</a></li> <li><a href="http://ru.uwenku.com/" target="_blank" title="поле вопросов и ответов">Русский</a></li> <li><a href="http://de.uwenku.com/" target="_blank" title="Frage - und - antwort - Park">Deutsch</a></li> <li><a href="http://es.uwenku.com/" target="_blank" title="Preguntas y respuestas">Español</a></li> <li><a href="http://hi.uwenku.com/" target="_blank" title="कार्यक्रम प्रश्न और उत्तर पार्क">हिन्दी</a></li> <li><a href="http://it.uwenku.com/" target="_blank" title="IL Programma di chiedere Park">Italiano</a></li> <li><a href="http://ja.uwenku.com/" target="_blank" title="プログラム問答園区">日本語</a></li> <li><a href="http://ko.uwenku.com/" target="_blank" title="프로그램 문답 단지">한국어</a></li> <li><a href="http://pl.uwenku.com/" target="_blank" title="program o park">Polski</a></li> <li><a href="http://tr.uwenku.com/" target="_blank" title="Program soru ve cevap parkı">Türkçe</a></li> <li><a href="http://vi.uwenku.com/" target="_blank" title="Đáp ứng viên">Tiếng Việt</a></li> <li><a href="http://fr.uwenku.com/" target="_blank" title="Programme interrogation Park">Française</a></li> </ul> </div> </div> </div> </div> </div> </footer> <!-- / footer --> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?f78a970f17b19a79fc477a3378096f29"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>