gpt4 book ai didi

javascript - JS : IF url from address equals, 发布到多个 div

转载 作者:行者123 更新时间:2023-11-28 09:14:40 25 4
gpt4 key购买 nike

我又回来了,带着一些火来回答一个实际的问题(这样我就不会再被火了)。我刚刚发布了我需要什么的抽象概念,并且我得到了一些很棒且立即的帮助。现在,是时候把这件事归结起来了。

这段代码可以工作,但是它不适用于多个页面,我不确定为什么。

    $(document).ready(function() {
var url = window.location.href;
if(url == "http://www.promilitarybusinessnetwork.com/continueSearch.asp?categoryID=108") {
$('#website').html('<p>This is the Apartments Category page</p>');
} else {
$('#website').empty();
}});

$(document).ready(function() {
var url = window.location.href;
if(url == "http://www.promilitarybusinessnetwork.com/continueSearch.asp?categoryID=13") {
$('#website').html('<p>This is the Business Category page</p>');
} else {
$('#website').empty();
}});

当发生多个实例时,上面的代码不起作用。因此,如果我删除了商务类别代码,并仅离开了公寓类别,则公寓将起作用。对于业务代码则反之亦然。

就目前情况而言,当我将两者都保留时,如上所示,业务类别是唯一显示的类别。

您可以在这里看到我想要完成的任务:

http://www.promilitarybusinessnetwork.com/

我正在修改和更新这个由我接管的网站。 “容器”和标题一样是可靠的,但页面需要帮助。这就是我想要做的,但我需要让它 100% 工作,然后才能深入设计它。网站使用 ASP,因此比较棘手。

最佳答案

使用if/else if/else:

$(document).ready(function() {
var url = window.location.href;
if (url === "http://www.promilitarybusinessnetwork.com/continueSearch.asp?categoryID=108") {
$("#website").html("<p>This is the Apartments Category page</p>");
} else if (url === "http://www.promilitarybusinessnetwork.com/continueSearch.asp?categoryID=13") {
$("#website").html("<p>This is the Business Category page</p>");
} else {
$("#website").empty();
}
});

这使得每个选项互斥。如果其中一个为true,它将执行,但其他都不执行。

关于javascript - JS : IF url from address equals, 发布到多个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15818370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com