6 回答
您可以简单地将onclick
处理程序添加到您的<tr>
标签,然后调用window.open("tel:+1800229933");
.
像这样:
<table>
<tr onclick="window.open('tel:900300400');">
<td>Phone: 900 300 400</td>
</tr>
</table>
改变这个:
<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>
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>
问题标题的确定答案,因此,不使用<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} ...
简短的答案
这将使您保持在同一个窗口中
window.location = "tel:495898694"
虽然这将打开另一个选项卡,然后拨打该号码
window.open('tel:900300400');
试试这个可能你会发现它很有帮助 https://www.theharnishes.com/phone.html