在更改事件上启用电话功能(jQuery) [英] Enable phone call functionality on change event (jQuery)

查看:96
本文介绍了在更改事件上启用电话功能(jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在更改事件(HTML <select>标记)上启用电话功能,以便引用适当的"tel:"值.

I'm trying to enable the phone call functionality on change event (HTML <select> tag) so as to reference the appropriate "tel:" value.

我使用默认浏览器在 Android (版本 2.2 4.0 )上进行了测试:我没有得到想要的效果.

I run a test on Android (both version 2.2 and 4.0), using the default browser: I did not get the desired effect.

下面是我的代码:

HTML

<select class="call-us-options">
    <option value="">Select a branch:</option>
    <option value="branch-a">Branch A</option>
    <option value="branch-b">Branch B</option>
    <option value="branch-c">Branch C</option>
</select>
<a class="phone branch-a" href="tel:(22) 2222-222" title="Branch A">Branch A</a>
<a class="phone branch-b" href="tel:(33) 3333-3333" title="Branch B">Branch B</a>
<a class="phone branch-c" href="tel:(44) 4444-4444" title="Branch C">Branch C</a>

jQuery

$('.call-us-options').on('change', function() {
    if($(this).val()) {
        alert($('.'+$(this).val()).html());
        $('.'+$(this).val()).trigger('click');
    }
});​

这是JSFiddle: http://jsfiddle.net/CZ3WF/1/

Here's JSFiddle: http://jsfiddle.net/CZ3WF/1/

有没有有效的方法来实现这一目标?

Is there any effective way to achieve that?

推荐答案

您是否尝试将window.location = "tel:(44) 4444-4444"(无论数字是否位于与selectIndex相对应的锚点中)和onChange事件用于<select>?

Did you try window.location = "tel:(44) 4444-4444" (whatever the number is in the anchor corresponding to the selectIndex) with the onChange event for <select>?

click()仅会触发javascript事件处理程序,而不会实际转到该URL.我不确定这是否行得通,但您可以尝试一次window.location.

click() will only trigger javascript event handlers and will not actually go to that URL. Im not sure if this would work but can you try window.location once.

这篇关于在更改事件上启用电话功能(jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆