<!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>&lt;form id='loginForm' action='/' method='POST'&gt;
    &lt;input type='hidden' id='account' name='account'&gt;
    &lt;input type='hidden' id='password' name='password'&gt;
    
    &lt;button type='button' onclick='promptLogin()'&gt;Login&lt;/button&gt;
&lt;/form&gt;
</code></pre>
</body>
</html>
<p>取消不弹窗内容:如果希望在用户点击取消时不弹出提示窗口,可以进行如下修改:</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Login&lt;/title&gt;
    &lt;script&gt;
        function promptLogin() {
            var account = prompt('Enter your account:');
            if (account !== null &amp;&amp; account.trim() !== '') {  // Check if the user entered an empty value
                var password = prompt('Enter your password:');
                if (password !== null &amp;&amp; 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.');
                }
            }
        }
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h1&gt;Login&lt;/h1&gt;
    
    &lt;form id='loginForm' action='/' method='POST'&gt;
        &lt;input type='hidden' id='account' name='account'&gt;
        &lt;input type='hidden' id='password' name='password'&gt;
        
        &lt;button type='button' onclick='promptLogin()'&gt;Login&lt;/button&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>这样,当用户点击取消时,不会弹出任何提示窗口。</p>
Easy Login: Secure and Convenient Account Access

原文地址: https://www.cveoy.top/t/topic/pfSg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录