当来自不同页面时,如何显示/隐藏单个元素

how to show/hide the single element when coming from different pages?

本文关键字:显示 元素 单个 隐藏 何显示      更新时间:2023-09-26

我有2个页面名称"A"和"B",两个页面都有一个链接,可以打开同一个页面"X"。但是页面"X"将根据它来自哪个页面显示/隐藏一些组件。

"X"页面上,我想在名为"X"的页面上显示/隐藏我的按钮。

如果我来自"页面A">它们应该是可见的。

如果我来自"B页">它们应该不可见。

====

============================================

我正在采取的方法是通过在页面 A 和 B 上的 URL 中传递变量/值来做到这一点。

HTML 代码页 A:-

<a data-fancybox-type="iframe" class="various marginLeft10 button" href="/Provision/Summary/MC-IT0401-ATUTEJA?abc">View Summary</a>

HTML 代码页 B:-

<a class="marginLeft50 button" href="/Provision/Summary/MC-IT0401-ATUTEJA?xyz">Confirm & Proceed</a>

第 X 页代码=

<div class="marginTop50 marginBottom valignBottom" role="button" id="summaryButtons">
    <input type="button" class="active" value="Back" id="stepSummaryBack">
    <input type="button" class="bigButton marginLeft50" value="Ready for Diagnostic" id="stepSummaryConfirm">
</div>

此特定 Div 应根据页面"A"或"B"的导航显示/隐藏。

我现在不确定如何确认 URL 以及我使用 jquery 传入"href"的变量(?abc?xyz)。

请指教。

如果有什么不清楚或需要更多详细信息,请告诉我。

所以在加载事件中你可以这样做。

 var URL = window.document.URL.toString();
           var vars = URL.split("?");
       then your variable should be vars[1];

我建议在渲染页面X时处理显示/隐藏决定,而不是在加载后使用javascript。您不需要在 url 中使用查询参数(?abc?xyz )。从控制器中的页面 X 请求访问HTTP_REFERER以查看请求是来自/page_a还是/page_b,然后在呈现页面 X 时使用该信息来确定是否包含按钮。