微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

一个相同的 onclick 事件在一个页面上起作用,但在另一个页面上不起作用;控制台说 Uncaught ReferenceError: is not defined at HTMLInputElement.onclick

如何解决一个相同的 onclick 事件在一个页面上起作用,但在另一个页面上不起作用;控制台说 Uncaught ReferenceError: is not defined at HTMLInputElement.onclick

我真的很茫然;什么都试过了,无济于事。

我正在一些网站上实施多种表格;对于所有这些,我想禁用提交按钮,直到有人选中“隐私政策”复选框。我创建了一个实际有效的函数:我已经在每个网站上实现了一个表单,并且在所有情况下,按钮的功能都按预期工作。

现在我正在尝试在这些网站之一上实现另一种形式,当发布时,按钮不起作用,并且控制台说该函数未定义(未捕获的 ReferenceError:enableSubmitButton 未定义)。

Console screenshot

Sources screenshot

我无法理解问题是什么。我使用 W3Schools 编辑器运行了代码 - 在那里运行良好。当我通过可视化编辑器(网站在 wordpress 上,编辑器是 Cornerstone)插入代码时,它也可以在那里工作。但不是在前端。我尝试重命名函数,但没有帮助。所以我只是不知道还能做什么。你能帮我找出问题吗?

这是我的代码

这是我介绍 onclick 事件的地方:

<div class='zcwf_row'><div class='zcwf_privacy'><div class='dIB vat' align='left'><input type='checkBox' name='privacyTool' onclick='enableSubmitButton(this)'></div><div class='dIB zcwf_privacy_txt'>By submitting your data,you agree to their transfer,storing or processing as stated in our Privacy Policy.</div></div></div><div class='zcwf_row'><div class='zcwf_col_fld'><input type='submit' id='formsubmit' class='formsubmit zcwf_button' value='Send' title='Send' disabled><input type='reset' style='visibility:hidden; ' class='zcwf_button' name='reset' value='Reset' title='Reset'></div></div>

这是我定义函数的地方:

<script>
    function enableSubmitButton(termsCheckBox){
        //If the checkBox has been checked
        if(termsCheckBox.checked){
            //Set the disabled property to FALSE and enable the button.
            document.getElementById("formsubmit").disabled = false;
        } 
        else{
            //Otherwise,disable the submit button.
            document.getElementById("formsubmit").disabled = true;
        }
   }
</script>

这是完整的表格(去掉了最多的样式和字段数量,缩短到最少以保持这里的简单)。请忽略奇怪的结构,它是 Zoho Webforms,除了大量重新设计之外,我无能为力。

<style>
    html,body{
        margin: 0px;
    }

    #crmWebToEntityForm.zcwf_lblTopBottom * {
        Box-sizing: border-Box;
    }
    #crmWebToEntityForm{
        text-align: left;
    }
    #crmWebToEntityForm * {
        direction: ltr;
    }
    .zcwf_lblTopBottom .zcwf_col_fld_inline input[type=text] {
        border: 1px solid #EEEEEE!important;
        resize: vertical;
        border-radius: 3px;
        float: left;
        background-color: #FFFFFF;
        padding: 20px;
    }
    .zcwf_lblTopBottom .zcwf_col_fld_inline {
        width: 50%!important;
        padding: 0px 6px 0px;
        position: relative;
        float:left;
        margin-top: 5px;
    }
    .zcwf_lblTopBottom .zcwf_privacy{
        padding: 6px!important;

    }
    .zcwf_lblTopBottom .wfrm_fld_dpnn{
        display: none;
    }
    .dIB{
        display: inline-block;
        max-width:90%!important;
    }
    .zcwf_lblTopBottom .zcwf_row_inline:after {
        content: '';
        display: table;
        clear: both;
    }
    .zcwf_lblTopBottom .zcwf_row_inline {
        margin: 0px 0px;
    }
    .zcwf_lblTopBottom .formsubmit {
        margin-right: 5px!important;
        cursor: pointer;
        color: #fff!important;
        font-size: 18px!important;
    }
    .zcwf_lblTopBottom .formsubmit:disabled {
        cursor: not-allowed!important;
    }
    .zcwf_lblTopBottom input[type="submit"]:disabled {
        cursor: not-allowed!important;
        background-color:#E9967A;
    }
    .zcwf_lblTopBottom .zcwf_button {
        margin-top: 2%;
        background-color: red;
        font-size: 18px;
    }
    .zcwf_lblTopBottom .zcwf_ckBox{
        float: left;
    }
</style>

<div class='zcwf_row_inline'>
    <div class='zcwf_col_fld_inline'>
            <input type='text' placeholder='First name' id='First_Name' name='First Name' maxlength='40'    style='min-width: 100%!important;'></input>
        <div class='zcwf_col_help'>
        </div>
    </div>

    <div class='zcwf_col_fld_inline'>
            <input type='text' placeholder='Last name' id='Last_Name' name='Last Name' maxlength='40' style='min-width: 100%!important;'></input>
       <div class='zcwf_col_help'>
       </div>
    </div>
</div>

<div class='zcwf_row'><div class='zcwf_privacy'><div class='dIB vat' align='left'><input type='checkBox' name='privacyTool' onclick='enableSubmitButton(this)'></div><div class='dIB zcwf_privacy_txt' style='font-size: 16px;font-family:"Oxygen",Open Sans;color:#445265;'>By submitting your data,storing or processing as stated in our Privacy Policy.</div></div></div><div class='zcwf_row'><div class='zcwf_col_fld'><input type='submit' id='formsubmit' class='formsubmit zcwf_button' value='Send' title='Send' disabled><input type='reset' style='visibility:hidden; ' class='zcwf_button' name='reset' value='Reset' title='Reset'></div></div>

<script>
    function enableSubmitButton(termsCheckBox){
        //If the checkBox has been checked
        if(termsCheckBox.checked){
            //Set the disabled property to FALSE and enable the button.
            document.getElementById("formsubmit").disabled = false;
        } 
        else{
            //Otherwise,disable the submit button.
            document.getElementById("formsubmit").disabled = true;
        }
   }
</script>
</form>
</div>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。