【问题标题】:HTML 5 : Click to call by using tel in href for alternate numbersHTML 5 : 单击以通过在 href 中使用 tel 来呼叫备用号码
【发布时间】:2017-01-31 04:15:14
【问题描述】:

我正在使用 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个数字?如果是,那怎么办?当用户单击它时,应选择随机数。任何帮助将不胜感激。提前致谢。

【问题讨论】:

    标签: html href tel


    【解决方案1】:

    您可以为此使用 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

    【讨论】:

    • 您的解决方案非常完美,解决了我的问题。谢谢哥们:)
    猜你喜欢
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 2015-04-18
    • 2020-05-07
    • 1970-01-01
    相关资源
    最近更新 更多