更改电话号码

时间:2017-12-04 10:45:24

标签: html

我正在尝试了解如何访问电话号码:

<div class="address__location">
  <p>
    Siddals Road
    <br> Derby DE1 2QD
  </p>
  <p>Main Phone:
    <a href="tel:0800123123&#10;         ">0800123123</a>
  </p>
</div>

我需要找到电话号码的html元素,以便我可以用其他号码替换它。

因此,如果我使用getElementbyID“xxx”,它将返回电话号码。

1 个答案:

答案 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