【发布时间】:2019-04-01 17:49:25
【问题描述】:
我正在尝试根据使用的设备分配 href 链接。但看起来 javascript 和 html 标记没有链接。这是正确的方法吗?
文件.html
<a id="chat" href="#" onclick="myChat();" target="_blank">
click here
</a>
<script src="chat.js"></script>
聊天.js
var whatsapp_num : 123456789;
function myChat() {
var isMobile = /iPhone|iPad|iPod|Android|webOS|BlackBerry/i.test(navigator.userAgent);
if (isMobile) {
document.getElementById("chat").href = "https://wa.me/" + whatsapp_num;
} else {
document.getElementById("chat").href = "https://web.whatsapp.com/send?phone=" + whatsapp_num;
}
}
【问题讨论】:
标签: javascript jquery html