简体   繁体   English

如何从<a>氚中</a>的<a>链接</a>获取锚点(#tag) <a>?</a>

[英]How can I get the anchor (#tag) from an <a> link in tritium?

I am trying to get the anchor tag from an anchor element link in the page eg 我试图从页面中的锚元素链接获取锚标记,例如

<a href="/page#reviews"> 

Is it possible to access the href so I can isolate #reviews and use it elsewhere in my Tritum script? 是否可以访问href以便我可以隔离#reviews并在我的Tritum脚本中的其他地方使用它?

Thanks! 谢谢!

Yes, it's possible, using a two step process. 是的,这是可能的,使用两步过程。

First, you can grab the value of the href attribute using the fetch() function. 首先,您可以使用fetch()函数fetch() href属性的值。

Then, working on the isolated string, you can use regular expressions to replace all the characters that occur in front of the hash/pound sign ( # ) with a blank. 然后,处理隔离的字符串,您可以使用正则表达式替换哈希/井号( # )前面出现的所有字符。

Here's an example using the Tritium Tester: http://tester.tritium.io/52503bcbe166ca7affa4944d90aae39808c8cd8e . 以下是使用Tritium Tester的示例: http//tester.tritium.io/52503bcbe166ca7affa4944d90aae39808c8cd8e

Note : This assumes that everything after the first # sign in the href attribute is what you're looking for. 注意 :这假定href属性中第一个#符号之后的所有内容都是您要查找的内容。

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

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