我如何返回价值' 170236'点击'查询'在这个例子中?
<a class="mylink"
href="https://www.mydomain.co.uk/help/contact/170236">Enquire</a>
我需要将其用于Google跟踪代码管理器中的变量
答案 0 :(得分:0)
function getLastSegment()
{
var links = document.getElementsByClassName('mylink');
var link = links[0].href;
alert(link.substr(link.lastIndexOf('/') + 1));
}
<a class="mylink"
href="https://www.mydomain.co.uk/help/contact/170236" onClick="getLastSegment()">Enquire</a>
答案 1 :(得分:0)
知道了!
function() {
var links = document.getElementsByClassName('mylink test tester');
var link = links[0].href;
var element = link.substr(link.lastIndexOf('/') + 1);
return element;
}