Easy Login: Secure and Convenient Account Access
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<script>
function promptLogin() {
var account = prompt('Enter your account:');
if (account !== null && account.trim() !== '') { // Check if the user entered an empty value
var password = prompt('Enter your password:');
if (password !== null && password.trim() !== '') { // Check if the user entered an empty value
document.getElementById('account').value = account;
document.getElementById('password').value = password;
document.getElementById('loginForm').submit();
} else {
alert('Password cannot be empty. Please try again.');
}
}
}
</script>
</head>
<body>
<h1>Login</h1>
<pre><code><form id='loginForm' action='/' method='POST'>
<input type='hidden' id='account' name='account'>
<input type='hidden' id='password' name='password'>
<button type='button' onclick='promptLogin()'>Login</button>
</form>
</code></pre>
</body>
</html>
<p>取消不弹窗内容:如果希望在用户点击取消时不弹出提示窗口,可以进行如下修改:</p>
<pre><code class="language-html"><!DOCTYPE html>
<html>
<head>
<title>Login</title>
<script>
function promptLogin() {
var account = prompt('Enter your account:');
if (account !== null && account.trim() !== '') { // Check if the user entered an empty value
var password = prompt('Enter your password:');
if (password !== null && password.trim() !== '') { // Check if the user entered an empty value
document.getElementById('account').value = account;
document.getElementById('password').value = password;
document.getElementById('loginForm').submit();
} else {
alert('Password cannot be empty. Please try again.');
}
}
}
</script>
</head>
<body>
<h1>Login</h1>
<form id='loginForm' action='/' method='POST'>
<input type='hidden' id='account' name='account'>
<input type='hidden' id='password' name='password'>
<button type='button' onclick='promptLogin()'>Login</button>
</form>
</body>
</html>
</code></pre>
<p>这样,当用户点击取消时,不会弹出任何提示窗口。</p>
原文地址: https://www.cveoy.top/t/topic/pfSg 著作权归作者所有。请勿转载和采集!