简体   繁体   English

如何将页面上的一个部分替换为锚点点击的另一个部分?

[英]How can i replace a section on a page with another section on a anchor click?

I have a tasks listing on right side of a page.我在页面右侧列出了一个任务。 On the other side there is a map shown inside a div .在另一边有一张地图显示在div I want to click on one of the tasks and get there details to replace map's div .我想单击其中一项任务并获取详细信息以替换地图的div After clicking in link when i refresh i should still get the task details not the map.在刷新时单击链接后,我仍然应该获得任务详细信息而不是地图。 Here is the code:这是代码:

 $(document).ready(function() { $("#show_task_detail").click(function() { $("#details").show(); $("#browse_tasks_map").hide(); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a href="javascript:;" class="list-group-item list-group-item-action task-detail-link " data-url="/task-details" data-id="{{ $post->id }}" id="show_task_detail"><input type="hidden" name="key" value="{{$post->id}}" />Post title</a> <div id="browse_tasks_map" style="position: relative; overflow: hidden;"></div> <div class="col-md-12 col-lg-12 col-xs-12 col-sm-12 task-detail-data" style="display: none;" id="details"></div>

You can use the addClass method of jquery可以使用jquery的addClass方法

    $(document).ready(function () {

    var hash = window.location.hash.split("#");
    if (hash.indexOf('show-details') > -1 ) {
        $("#details").addClass('show');
        $("#browse_tasks_map").addClass('hidden');
    }

    $("#show_task_detail").click(function () {
        $("#details").addClass('show');
        $("#browse_tasks_map").addClass('hidden');
        window.location.hash = "show-details";

    });
});

Where the css would be, css 所在的位置,

.show{
display: block;
}

.hidden{
display: none;
}
  1. When clicking the link set anchor part of the url单击链接时设置 url 的锚部分

  2. When rendering the page, check URL for the anchor tag渲染页面时,检查锚标记的 URL

     function showDetails() { $("#details").show(); $("#browse_tasks_map").hide(); } $(document).ready(function() { if (document.hash == 'details') { showDetails(); } $("#show_task_detail").click(function () { showDetails(); document.location.hash = 'details' }); });

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

相关问题 当我有一个锚标记引用同一页面中的另一个部分时,如何使它不立即显示我点击它 - When I have an anchor tag refrencing another section in the same page, how do I make it not to display immediately i have clicked it 我如何将用户从另一个HTML页面重定向到HTML页面上的“部分”? - How can i redirect the user to a 'section' on an html page from another html page? 定位标记重定向到另一部分 - anchor tag redirecting to another section 在我的HTML页面的部分外部单击时如何隐藏部分? - How to hide a section when click outside the section in my HTML page? 提交表单数据后如何转移到另一页的部分? - how can i transfer to section of another page after submit form data? Fullpage.js如何链接到另一个带有<a>元素的</a> html页面 - Fullpage.js how can I link to another html page with <a> element in section 如果没有定位标记,如何从第1页跳至第2页的特定部分 - How to jump from page 1 to the specific section in page 2 if there are no anchor tags 如何用 iframe 替换 bigcommerce 结帐页面的部分 - how to replace section of a bigcommerce checkout page with an iframe 单击后如何隐藏表格部分并显示 - How Can i make a table section hidden and display after click 如何使用锚标记在react / preact中导航到页面的特定部分 - How to use anchor tag to navigate to particular section of page in react/preact
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM