我的网站上有这个 jQuery 代码
if(window.location.href.indexOf("mysite.com/") != -1){
$("#announcer_box").hide();
我想在我的主页上显示这个元素 ID,但从所有其他页面中排除它。这怎么可能?
我正在使用wordpress。
我的网站上有这个 jQuery 代码
if(window.location.href.indexOf("mysite.com/") != -1){
$("#announcer_box").hide();
我想在我的主页上显示这个元素 ID,但从所有其他页面中排除它。这怎么可能?
我正在使用wordpress。
在您的主页上,给<html>
or<body>
标记一个特殊的类(例如“主页”):
<html class='homepage'> <!-- plus any other classes you want/need -->
然后在你的 CSS 中:
#announcer_box { display: none; }
.homepage #announcer_box { display: block; }
这应该有效:
if ((window.location.protocol + "//" + window.location.hostname + "/") != (window.location.href)) {
$("#announcer_box").hide();
}
那么,您可能有<body class="homepage">
类似的东西?
if($("body").hasClass("home")
$("#announcer_box").hide();