我这里有这段代码:
<html>
<body style="color:white;background-color:#222222">
<center>
<br>
<input type="text" id="username"> Username</input>
<br>
<input type="text" id="password"> Password</input>
<br><br>
<button onclick="test()">Submit</button>
<p id="url"/>
<script type="text/javascript">
function test(){
var userInput = document.getElementById("username").value;
var userPass = document.getElementById("password").value;
document.getElementById("url").innerHTML = encodeURI('http://'+userInput+':'+userPass+'@'+window.location.hostname+':81/Home/');
}
</script>
</center>
</body>
</html>
它输出一个 有效 的 url。当我指定正确的密码时,它会将我登录到受密码保护的文件夹中。 唯一的问题是,我希望“提交”按钮自动将我重定向到指定页面,而不是显示 url。
我什么都试过了。 请帮忙。 谢谢。
最佳答案
请检查:
function test(){
var userInput = document.getElementById("username").value;
var userPass = document.getElementById("password").value;
location.href = encodeURI('http://'+userInput+':'+userPass+'@'+window.location.hostname+':81/Home/');
}
关于javascript - 使用网页登录apache服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53586559/