简体   繁体   English

如何使用锚标签点击特定跨度

[英]How to use anchor tag to click on particular span

all sorry for the very basic or maybe a silly question but I was trying to do something which I am not sure, can be done by using an anchor tag or not.对于这个非常基本的或者可能是一个愚蠢的问题,我感到很抱歉,但我正在尝试做一些我不确定的事情,是否可以通过使用锚标签来完成。 After searching over the internet I didn't find any perfect solution for that so here I am writing this question.在互联网上搜索后,我没有找到任何完美的解决方案,所以我在这里写这个问题。

Problem - I want to redirect my page from index.php to about.php , and I also want to open one div that can be only visible if we click on it.问题 - 我想将我的页面从index.php重定向到about.php ,我还想打开一个只有当我们点击它时才能看到的 div。 How to do that using an anchor tag?如何使用锚标签来做到这一点?

I tried - <a href="about#my_div_id"> unfortunately, It didn't work I think maybe because I have to also click on that particular div to make it open.我试过 - <a href="about#my_div_id">不幸的是,它没有用我想可能是因为我还必须点击那个特定的 div 才能打开它。 Anyone can please help me out I need some solution to do this.任何人都可以请帮助我,我需要一些解决方案来做到这一点。 I am using angularJs so if it can be done by that, please help!我正在使用 angularJs 所以如果可以这样做,请帮忙!

Could you parse the URL in JavaScript on page load, open the div, and set document.documentElement.scrollTop to the position of the div on your page?您能否在页面加载时解析 JavaScript 中的 URL ,打开 div,并将document.documentElement.scrollTop设置为您页面上的 position?

Something like:就像是:

# On page load:
#   if $parsedURL has $hash:
#     div.show()
#     window.scrollTo(div.position)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM