0

尝试根据子域替换和隐藏某些元素。例如,如果 url 是“www.uownrealestate.com”,则加载普通站点,但如果它是“justin2.uownrealestate.com”,则隐藏包含带有文本“Agents”的锚链接的元素。

$(document).ready(function() {
    var option = 'justin2';
    var full = window.location.host
    //window.location.host is subdomain.domain.com
    var parts = full.split('.')
    var subDomain = parts[0]
    var domain = parts[1]

    if (subDomain == option) {

        showDiv();
    }
});

function showDiv() {
    $("li:has(a:contains('Agents'))").hide();

}​

编辑

$(document).ready(function() {
var option = 'justin2';


var full = window.location.host
if(full.indexOf(option) > -1){
showDiv(); 
}
});
function showDiv() {
$("li:has(a:contains('Agents'))").hide();

}

仍然没有任何事情发生。还有其他建议吗?此脚本也在外部 js 文件中。这根本不重要吗?这是 li 元素的片段。

  <li><a href="only-at-uown.html">Only at uOwn</a>
    <ul>
<li><a href="showing-simulations.html"><span> Showing Simulations</span></a></li>
<li><a href="3d-mapping.html"><span> 3D Mapping</span></a></li>
<li><a href="solar-signs.html"><span> Solar-Powered Yard Signs</span></a></li>
<li><a href="paper-free-office.html"> Paper-Free Offices</a></li>
    <li><a href="prestige-package.html"> Prestige Package</a></li>
<li><a href="only-at-uown.html"> <em>Much more...</em></a></li>

    </ul>
   </li>


 <li><a href="realtors-agents.html">Agents</a></li>


 <li><a href="3d-showcase.html">3D Showcase</a></li>
4

1 回答 1

1

尝试使用.indexOf(

var full = window.location.host;
if(full.indexOf(option) > -1){
   showDiv(); 
}
于 2012-12-04T17:09:02.067 回答