我希望我的網址在頁面加載時顯示在文本字段中。 我試過,但沒有奏效:在頁面加載時在文本字段中插入當前網址
function getUrl() {
var url = document.URL;
document.getElementById("textfield").value = url;
}
<input type="text" name="textfield" id="textfield" readonly="true" onload="getUrl()" value="">
嘗試:VAR URL = window.location.href; – darron614