例如,我需要检查DHL跟踪号码,并要求用户输入他们的跟踪号码进行检查。这是输入:
Name: <input type="text" id="myText" >
<button onclick="myFunction()">check tracking</button>
DHL让它添加代码调整网址,例如:https://nolp.dhl.de/nextt-online-public/en/search?piececode=
并加上跟踪代码。演示网址为:https://nolp.dhl.de/nextt-online-public/en/search?piececode=48484848484848484
这是Javascript:
function myFunction() {
var inputed_code = document.getElementById("myText").value ;
var dhlurl = "https://nolp.dhl.de/nextt-online-public/en/search?piececode="
var new_url = dhlurl + inputed_code ;
window.open("new_url", "_blank");
}
但它不需要网址:(
答案 0 :(得分:1)
那是因为你正在使用"new_url"
,这是一个字面的strting,而不是new_url
,变量
function myFunction() {
var inputed_code = document.getElementById("myText").value ;
var dhlurl = "https://nolp.dhl.de/nextt-online-public/en/search?piececode="
var new_url = dhlurl + inputed_code ;
window.open(new_url, "_blank");
}