[英]HTML & PHP - Type a telephone number, and call it
我寫了代碼,但是沒有用。
碼:
<?php
$number = $_GET["tel"];
echo '<form action="/" method="get">
<a>Enter the phone number, what you want to call</a>
<input type="tel" name="tel"/>
<input type="submit" onclick="call()" value="Call"/>
</form>
<script>
function call() {
window.open("tel:$number");
}
</script>
';
在PHP中,字符串中的變量只能用雙引號引起來 。 將單引號更改為雙引號,以使$number
在字符串中起作用。
有關更多詳細信息,請參見此SO帖子 。
因此,您的代碼應如下所示:
<?php
$number = $_GET["tel"];
echo "<form action='/' method='get'>
<a>Enter the phone number, what you want to call</a>
<input type='tel' name='tel' />
<input type='submit' onclick='call()' value='Call' />
</form>
<script>
function call() {
window.open('tel:$number');
}
</script>
";
?>
但是這段代碼很奇怪。 流程如下:
$_GET
變量tel
(假設表格已經發送) echo
顯表格 $_GET["tel"]
中的數字, 而不是表單中的數字 window.open()
已經發生 這是一個沒有PHP(也沒有實際發送表單)的替代解決方案:
<form action='/' method='get'>
<a>Enter the phone number, what you want to call</a>
<input type='tel' name='tel' />
<input type='submit' onclick='call();return false;' value='Call' />
</form>
<script>
function call() {
var number = document.querySelector("input[name=tel]").value;
window.open('tel:' + number);
}
</script>
可以在JSFiddle.net上看到它的工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.