show the inputed email in the next page above the password field in

ε祈祈猫儿з 提交于 2020-01-24 20:47:26

问题


I am creatig a login system. I want the user to input the email and then click next. Then the user will be redirected to the password input page. I want to put he email that the user has typed above the password field.

Do someone know how to do it?


回答1:


You can use forms to do this, but really we try not to use forms anymore. A more modern way is to use localStorage.

Also, you cannot do this with just HTML and CSS. You need to use javascript also.

Here is an example of how it might work.

PAGE ONE:

<label for="emlInput">Email: </label>
<input type="email" id="emlInput" />
<button id="btnNext">Next</button>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        const btnNext = document.getElementById('btnNext');
        btnNext.addEventListener("click", advancePage, false);
    });

    function advancePage() {
        const elEml = document.getElementById('emlInput');
        localStorage.setItem('eml', elEml.value);
        window.location.href = "t2.html";
    }
</script>

PAGE2

<div>
    <h2>Password For: <span id="emlSpan"></span></h2>
</div>
<label for="pwd">Password: </label>
<input type="password" id="pwd" />

<script>
    document.addEventListener("DOMContentLoaded", function() {
        const ls = localStorage.getItem('eml');
        const eml = document.getElementById('emlSpan');
        eml.innerText = ls;
    });
</script>


来源:https://stackoverflow.com/questions/59521218/show-the-inputed-email-in-the-next-page-above-the-password-field-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!