繁体   English   中英

网址参数和具体条件

[英]Url parameter and specific conditions

我有这个网址

http://www.example.com/ln-en/Category/Product/Product-A/Details

如果我使用这个if条件

(window.location.href.split("/")[6] !== "Product-A" || window.location.href.split("/")[6] !== "Product-B" || window.location.href.split("/")[6] !== "Product-C" || window.location.href.split("/")[6] !== "Intro" || window.location.href.split("/")[6] !== "vol-A-Free" || window.location.href.split("/")[6] !== "vol-B")

我认为结果true

但是如果我只使用这个

window.location.href.split("/")[6] !== "Product-A"

我以我本来希望提供的第一个条件为false 有什么事吗

window.location.href.split("/")[6]"Product-A"

因此:

window.location.href.split("/")[6] !== "Product-A"false

window.location.href.split("/")[6] !== "Product-B"true

window.location.href.split("/")[6] !== "Product-"A" || window.location.href.split("/")[6] !== "Product-B" 

是相同的

false || true

这是true

您可能想在测试中使用&&条件。

该表达式将始终返回true因为总是存在|之一。 (或)符合条件的标准。 您可以使用数组indexOf代替:

var products =["Product-A", "Product-B", "Product-C", "Intro", "vol-A-Free", "Vol-B"];

console.log(products.indexOf(window.location.href.split("/")[6]));

要么

console.log(products.indexOf(window.location.href.split("/")[6])>-1);

节目<div>当满足特定的 URL 参数时</div><div id="text_translate"><p>我在 Google 表格中有一个表单,它将 URL 参数传递到页面,然后该页面应显示基于 URL 参数的内容。</p><p> 因此,如果有人在 Google Sheet 中检查“item 1”和“item 2”,参数将按如下方式传递:</p><p> <a href="https://my-url.com/?item1=value1&amp;item2=value2" rel="nofollow noreferrer">https://my-url.com/?item1=value1&amp;item2=value2</a></p><p> 现在有几个 div 容器,设置为 display:none 和 css。 当满足 URL 参数时,应该会显示隐藏的 div 容器。 所以 html 是:</p><pre> &lt;div class="hidden" id="value1"&gt;This content should show, when the URL parameter value 1 is passed&lt;/div&gt; &lt;div class="hidden" id="value2"&gt;This content should show, when the URL parameter value 2 is passed&lt;/div&gt;</pre><p> 我在网上找到了一些代码,它几乎可以做到这一点,但它一次只能显示一个 div: <a href="https://jennamolby.com/how-to-display-dynamic-content-on-a-page-using-url-parameters/" rel="nofollow noreferrer">https://jennamolby.com/how-to-display-dynamic-content-on-a-page-using -url参数/</a></p><p> 我的问题是,对于每个传递的参数,必须显示一个字段。</p><p> 谁能帮我这个? 无论如何,我真的不是 js 专家。</p></div>

[英]Show <div> when a specific URL Parameter is met

暂无
暂无

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

相关问题 更改URL的特定参数 使用JavaScript和特定条件在href网址上添加参数 用于匹配具有多个条件的特定 URL 的正则表达式 在不同条件下替换字符串[url参数]之间的值 节目<div>当满足特定的 URL 参数时</div><div id="text_translate"><p>我在 Google 表格中有一个表单,它将 URL 参数传递到页面,然后该页面应显示基于 URL 参数的内容。</p><p> 因此,如果有人在 Google Sheet 中检查“item 1”和“item 2”,参数将按如下方式传递:</p><p> <a href="https://my-url.com/?item1=value1&amp;item2=value2" rel="nofollow noreferrer">https://my-url.com/?item1=value1&amp;item2=value2</a></p><p> 现在有几个 div 容器,设置为 display:none 和 css。 当满足 URL 参数时,应该会显示隐藏的 div 容器。 所以 html 是:</p><pre> &lt;div class="hidden" id="value1"&gt;This content should show, when the URL parameter value 1 is passed&lt;/div&gt; &lt;div class="hidden" id="value2"&gt;This content should show, when the URL parameter value 2 is passed&lt;/div&gt;</pre><p> 我在网上找到了一些代码,它几乎可以做到这一点,但它一次只能显示一个 div: <a href="https://jennamolby.com/how-to-display-dynamic-content-on-a-page-using-url-parameters/" rel="nofollow noreferrer">https://jennamolby.com/how-to-display-dynamic-content-on-a-page-using -url参数/</a></p><p> 我的问题是,对于每个传递的参数,必须显示一个字段。</p><p> 谁能帮我这个? 无论如何,我真的不是 js 专家。</p></div> 具有特定参数的角度路由匹配 url 有没有办法用php检查网址中的特定参数? 获取 URL 参数并过滤掉特定参数 正则表达式以从URL获取特定参数 Javascript获取以特定字符串开头的URL参数
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM