41
4

6 回答 6

90

您可以简单地将onclick处理程序添加到您的<tr>标签,然后调用window.open("tel:+1800229933");.

像这样:

<table>
  <tr onclick="window.open('tel:900300400');">
    <td>Phone: 900 300 400</td>
  </tr>
</table>

于 2013-07-27T11:34:36.547 回答
23

改变这个:

<table>
  <tr>
    <td>Phone: 900 300 400</td>
  </tr>
</table>

至:

<table>
  <tr>
    <td>
      <a href="tel:+900300400">Phone: 900 300 400</a>
    </td>
  </tr>
</table>
于 2013-07-27T11:36:08.527 回答
17

Find the cell content with jQuery, replace the "Phone:" part and make it a link. The selection of the cell with a class is one way of doing it. Another would be to select in the real table the cell with a code similar to "the second cell in each row of the table". Here a working example:

<html>
  <head>
    <title>Test</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>
      $(function() {
        $('.phonecell').click(function() {
          var PhoneNumber = $(this).text();
          PhoneNumber = PhoneNumber.replace('Phone:', '');
          window.location.href = 'tel://' + PhoneNumber;
        });
      });
    </script>
  </head>
  <body>
    <table>
      <tr>
        <td class="phonecall">Phone: 900 300 400</td>
      </tr>
    </table>
  </body>
</html>
于 2013-07-27T12:08:43.227 回答
7

问题标题的确定答案,因此,不使用<a>标签是制作一个辅助函数来模拟的动作<a href="tel:

const simulateCall = phoneNumber => window.open(`tel:${phoneNumber}`, '_self');

目标 _self导致我们有一个完全像调用模拟一样的外观,就像点击一样<a href="tel:

现在simulateCall辅助函数可以在任何地方使用。像我的情况:

const callHandler = phoneNumber => () => {
  // I want to do something here then make a call
  simulateCall(phoneNumber);
};

~~~

<SomeComponent onClick={callHandler} ...
于 2020-04-12T20:16:08.893 回答
0

简短的答案

这将使您保持在同一个窗口中

window.location = "tel:495898694"

虽然这将打开另一个选项卡,然后拨打该号码

window.open('tel:900300400');
于 2021-07-12T00:58:13.200 回答
0

试试这个可能你会发现它很有帮助 https://www.theharnishes.com/phone.html

于 2021-03-25T00:28:49.777 回答