程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何更改脚本中的 CHANGE ME 文本大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何更改脚本中的 CHANGE ME 文本?

开发过程中遇到如何更改脚本中的 CHANGE ME 文本的问题如何解决?下面主要结合日常开发的经验,给出你关于如何更改脚本中的 CHANGE ME 文本的解决方法建议,希望对你解决如何更改脚本中的 CHANGE ME 文本有所启发或帮助;

我在我的电脑上试过这个代码,但它不起作用,有谁知道为什么?

有这段文字包含文字 CHANGE ME。它包含一个“警告”的 ID,现在我想在有人点击登录按钮时更改该文本。它在我的电脑上不起作用。我做错了什么?

    <!DOCTYPE HTML>
    <HTML style="height: 100%; wIDth: 100%; margin: 0;">
    <head>
        <title></title>
    </head>
    
    <body style="display: flex; height: 100%; wIDth: 100%; margin: 0;">
    <!-- maxlength="20"> -->
    
    <form style="margin: auto; border: solID; padding: 10px;">
        
        <label style="Font-size: 40px;"> Welcome! </label>
        <br>
        <input ID="passwordText" type="password" placeholder="password" maxlength="20">
        <input ID="loginbutton" type="button" value="Login" onclick="submit()">
        <br>
        <p ID="warning">CHANGE ME</p>
    
    </form>
    
    <script>
    
        function toggleWarningText(text)
        {
            document.getElementByID('warning').INNERHTML = text;
        }
    
        function submit()
        {
            //toggleWarningText("");

            let password = document.GetElementByID("passwordText").value;

            //This togglewarningtext doesn't work
            toggleWarningText(password);
    
            //This below doesn't work either
            if(password.length < 4)
            {
                toggleWarningText("The password must be at least 4 characters long");
            } 
            else 
            {
                toggleWarningText(password);
            }    
        }
    
    </script>
    
    </body>
    
    </HTML>

解决方法

我认为您正在寻找

function toggleWarningText(text)
    {
        document.getElementById('warning').value= text;
    }

而不是 .innerHTML

,

更改 submit() 函数名称。 它调用 form submit() 函数。

  <!DOCTYPE html>
    <html style="height: 100%; width: 100%; margin: 0;">
    <head>
        <title></title>
    </head>
    
    <body style="display: flex; height: 100%; width: 100%; margin: 0;">
    <!-- maxlength="20"> -->
    
    <form style="margin: auto; border: solid; padding: 10px;">
        
        <label style="font-size: 40px;"> Welcome! </label>
        <br>
        <input id="passwordText" type="password" placeholder="password" maxlength="20">
        <input id="loginButton" type="button" value="Login" onclick="clicked()">
        <br>
        <p id="warning">CHANGE ME</p>
    
    </form>
    
    <script>
    
        function toggleWarningText(text)
        {
            document.getElementById('warning').innerHTML = text;
        }
    
        function clicked()
        {
            //toggleWarningText("");

            let password = document.getElementById("passwordText").value;

            //This togglewarningtext doesn't work
            toggleWarningText(password);
    
            //This below doesn't work either
            if(password.length < 4)
            {
                toggleWarningText("The password must be at least 4 characters long");
            } 
            else 
            {
                toggleWarningText(password);
            }    
        }
    
    </script>
    
    </body>
    
    </html>

@H_262_40@

大佬总结

以上是大佬教程为你收集整理的如何更改脚本中的 CHANGE ME 文本全部内容,希望文章能够帮你解决如何更改脚本中的 CHANGE ME 文本所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。