如何获取<a> tag in html?

时间:2017-09-16 10:59:17

标签: html hyperlink tags

I am having trouble with the anchor tag of HTML. I have something like this:

  1. Topic1
  2. Topic2
  3. Topic3

where Topic1, Topic2 and Topic3 are the link texts. On clicking any of these, it will take me to the content.html page but the content of this page differs only on the text which is clicked (ie.) how do I get the link text in the content.html page?

On an update to the database I will have more topics generated. So I want this link to function dynamically.

3 个答案:

答案 0 :(得分:0)

请先包含jquery $('a').click(function(){ alert($(this).attr('href')); // or alert($(this).hash();  });

答案 1 :(得分:0)

您必须将文本作为参数(使用查询字符串)发送到content.html页面。然后,当content.html页面加载时,您可以使用javascript从查询字符串中提取参数,并填充您的页面。

答案 2 :(得分:0)

如果您转到特定网站的页面content.html,则content.html文件必须包含id="topic1"id="topic2"id="topic3"的不同部分。

<a href="https://www.example.com/content.html/#topic1">Topic1</a>
<a href="https://www.example.com/content.html/#topic2">Topic2</a>
<a href="https://www.example.com/content.html/#topic3">Topic3</a>

content.html

<div id="topic1">---contains----</div>
<div id="topic2">---contains----</div>
<div id="topic3">---contains----</div>