名称属性抑制onClick功能

发布于 2025-01-24 02:32:31 字数 1069 浏览 2 评论 0原文

下面的代码正常工作,它更改了密码类型,以显示输入为文本。 将名称属性添加到“密码”以从PHP中的$ post检索数据时,会出现ProLEM。我认为可能没有一种方法可以在没有“名称”的情况下获取数据的数据,但是我的reasearch表明,没有“名称”属性,无法检索数据。

问题:如何带入名称属性并保持我的功能?

            <div>
                <label for="password">Passwort (8 min. pls. )</label>
                <input type="password" id="password" minlenght="8" required>
            </div>
            <div>
                <label for="anzeigen">Passwort anzeigen</label>
                <input type="checkbox" onclick="anzeigen()" >
            </div>
            <div>
                <input type="submit" id="mitmachen" value="mitmachen">
            </div>
        </form>
        <script>
            function anzeigen() {
                var x = document.getElementById("password");
                if (x.type === "password") {
                    x.type = "text";
                }else {
                    x.type = "password";
                }
            }
        </script>

The code below works fine, it changes the type of password to reveal the input as text.
The prolem appears when adding a name attribut to "password" in order to retrieve data from $POST in php. I thought there might be a way to get the data on serverside without a "name", but my reasearch showed that without a "name" attribute no data can be retrieved.

Question: How to bring in the name attribute and keep my functionality?

            <div>
                <label for="password">Passwort (8 min. pls. )</label>
                <input type="password" id="password" minlenght="8" required>
            </div>
            <div>
                <label for="anzeigen">Passwort anzeigen</label>
                <input type="checkbox" onclick="anzeigen()" >
            </div>
            <div>
                <input type="submit" id="mitmachen" value="mitmachen">
            </div>
        </form>
        <script>
            function anzeigen() {
                var x = document.getElementById("password");
                if (x.type === "password") {
                    x.type = "text";
                }else {
                    x.type = "password";
                }
            }
        </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文