你好。我在使用 javascript 时遇到了一些问题。如何在 whatsapp api 中使用 var **mobile** 作为 phone 号码
hi. i have some issue using javascript. how to use var **mobile** as phone number in whatsapp api
我只使用 Html + Javascript。
html:
<input type="text" id="mobile" placeholder="Mobile Number" class="input-control">
<img src="pic/download.jpg" onclick="chat()">
Javascript:
function chat(){
var **mobile** = document.getElementById("mobile").value
location.href="https://api.whatsapp.com/send?phone=**"mobile"**&text=Hello%20World
}
您可以如下所示进行操作。但请注意,我注释掉了实际上会将浏览器重定向到 Whosebug 之外的行。
function chat(){
let mobile = document.getElementById("mobile").value;
//assemble the new URL
let newUrl = `https://api.whatsapp.com/send?phone=${mobile}&text=Hello%20World`;
alert(newUrl);
/*** uncomment next line to redirect the browser ***/
//location.href=newUrl;
}
<input type="text" id="mobile" placeholder="Mobile Number" class="input-control">
<img src="pic/download.jpg" onclick="chat()">
我只使用 Html + Javascript。
html:
<input type="text" id="mobile" placeholder="Mobile Number" class="input-control">
<img src="pic/download.jpg" onclick="chat()">
Javascript:
function chat(){
var **mobile** = document.getElementById("mobile").value
location.href="https://api.whatsapp.com/send?phone=**"mobile"**&text=Hello%20World
}
您可以如下所示进行操作。但请注意,我注释掉了实际上会将浏览器重定向到 Whosebug 之外的行。
function chat(){
let mobile = document.getElementById("mobile").value;
//assemble the new URL
let newUrl = `https://api.whatsapp.com/send?phone=${mobile}&text=Hello%20World`;
alert(newUrl);
/*** uncomment next line to redirect the browser ***/
//location.href=newUrl;
}
<input type="text" id="mobile" placeholder="Mobile Number" class="input-control">
<img src="pic/download.jpg" onclick="chat()">