[英]HTML 5 : Click to call by using tel in href for alternate numbers
我正在使用 href 实现点击呼叫。
<a href="tel:+919876543210">Click here to call</a>
它适用于单个号码。 但我需要在 href 中给出 2 个数字作为备用数字。
我试过这个,
<a href="tel:+919876543210, +919876543211">Click here to call</a>
我也尝试过以下方法,
<a href="tel:+919876543210, tel:+919876543211">Click here to call</a>
但它只需要第一个数字。 是否可以在href中添加2个数字? 如果是,那么如何? 当用户单击此按钮时,应选择随机数。 任何帮助将不胜感激。 提前致谢。
您可以为此使用 JavaScript :-)
下面是一个简单的网页的一些代码,应该可以解决你的问题
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script type="text/javascript">
// The Phone numbers
var phoneNumbers = [
"+919876543210",
"+919876543211"
];
/**
* Returns a random integer between min (inclusive) and max (inclusive)
* Using Math.round() will give you a non-uniform distribution!
*/
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function call() {
// Get min and max index of the phone number array
min = 0;
max = phoneNumbers.length - 1;
// get the random phone number
phoneNumberToCall = phoneNumbers[getRandomInt(min, max)];
// Call the random number
window.open("tel:" + phoneNumberToCall);
}
</script>
</head>
<body>
<a onclick="call()" href="">Click here to call</a>
</body>
</html>
我从这里得到了随机数生成器 => https://stackoverflow.com/a/1527820/2627137
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.