我正在尝试了解如何访问电话号码:
<div class="address__location">
<p>
Siddals Road
<br> Derby DE1 2QD
</p>
<p>Main Phone:
<a href="tel:0800123123 ">0800123123</a>
</p>
</div>
我需要找到电话号码的html元素,以便我可以用其他号码替换它。
因此,如果我使用getElementbyID“xxx”,它将返回电话号码。
答案 0 :(得分:2)
该元素没有设置id
属性。
但是,您可以使用document.querySelector
并传递a[href^="tel:"]
来使用其他选择器。这将搜索具有a
属性的href
元素,这些元素以文本^=
开头( tel:
表示)。< / p>
所以
var telephoneNode = document.querySelector('a[href^="tel:"]');
telephoneNode.textContent = 'some other phone'; // change the displayed text
telephoneNode.href = 'some other url'; // change the href and in effect where the link points to