Javascript 一个相同的onclick事件可以在一个页面上工作,但不能在另一个页面上工作;控制台表示未捕获引用错误:未在HTMLInputElement.onclick上定义
我在这里真是不知所措;什么都试过了,都没用 我在几个网站上实现了几个表单;对于所有这些,我想禁用提交按钮,直到有人选中“隐私策略”复选框。我创建了一个实际工作的功能:我已经在每个网站上实现了一个表单,并且在所有情况下按钮的功能都如预期的那样工作 现在,我正试图在其中一个网站上实现另一个表单,当发布时,按钮不起作用,控制台说该函数未定义(UncaughtReferenceError:enableSubmitButton未定义) 我不明白问题是什么。我用W3Schools编辑器运行了代码,它在那里工作得很好。当我通过可视化编辑器(网站在Wordpress上,编辑器是基石)插入代码时,它也可以在那里工作。不过,不是在前端。我尝试重新命名该函数,但没有帮助。所以我不知道还能做什么。你能帮我找出这个问题吗 这是我的密码: 这是我介绍onclick事件的地方:Javascript 一个相同的onclick事件可以在一个页面上工作,但不能在另一个页面上工作;控制台表示未捕获引用错误:未在HTMLInputElement.onclick上定义,javascript,html,jquery,onclick,buttonclick,Javascript,Html,Jquery,Onclick,Buttonclick,我在这里真是不知所措;什么都试过了,都没用 我在几个网站上实现了几个表单;对于所有这些,我想禁用提交按钮,直到有人选中“隐私策略”复选框。我创建了一个实际工作的功能:我已经在每个网站上实现了一个表单,并且在所有情况下按钮的功能都如预期的那样工作 现在,我正试图在其中一个网站上实现另一个表单,当发布时,按钮不起作用,控制台说该函数未定义(UncaughtReferenceError:enableSubmitButton未定义) 我不明白问题是什么。我用W3Schools编辑器运行了代码,它在那
<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>
提交您的数据即表示您同意按照我们的隐私政策进行传输、存储或处理。
这就是我定义函数的地方:
<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>
功能启用提交按钮(termsCheckBox){
//如果已选中该复选框
如果(termsCheckBox.checked){
//将disabled属性设置为FALSE并启用按钮。
document.getElementById(“formsubmit”).disabled=false;
}
否则{
//否则,请禁用“提交”按钮。
document.getElementById(“formsubmit”).disabled=true;
}
}
这是完整的表单(去掉了大多数样式,并将字段数缩短到最小,以保持此处的简单性)。请忽略这个奇怪的结构,它是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, 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>
</form>
</div>
html,正文{
边际:0px;
}
#crmWebToEntityForm.zcwf_lblTopBottom*{
框大小:边框框;
}
#crmWebToEntityForm{
文本对齐:左对齐;
}
#crmWebToEntityForm*{
方向:ltr;
}
.zcwf\u lblTopBottom.zcwf\u col\u fld\u内联输入[类型=文本]{
边框:1px实心#EEEEEE!重要;
调整大小:垂直;
边界半径:3px;
浮动:左;
背景色:#FFFFFF;
填充:20px;
}
.zcwf_lblTopBottom.zcwf_col_fld_inline{
宽度:50%!重要;
填充:0px 6px 0px;
位置:相对位置;
浮动:左;
边缘顶部:5px;
}
.zcwf_lbltopbotom.zcwf_隐私{
填充:6px!重要;
}
.zcwf_lblTopBottom.wfrm_fld_dpNn{
显示:无;
}
.dIB{
显示:内联块;
最大宽度:90%!重要;
}
.zcwf\u lbltopbotom.zcwf\u行\u内联:之后{
内容:'';
显示:表格;
明确:两者皆有;
}
.zcwf\u lbltopbotom.zcwf\u行\u内联{
保证金:0px 0px;
}
.zcwf\u lblTopBottom.formsubmit{
右边距:5px!重要;
光标:指针;
颜色:#fff!重要;
字体大小:18px!重要;
}
.zcwf\u lblTopBottom.formsubmit:已禁用{
光标:不允许!重要;
}
.zcwf\u lbltopbotom输入[type=“submit”]:已禁用{
光标:不允许!重要;
背景色:#E9967A;
}
.zcwf\u lbltopbotom.zcwf\u按钮{
利润率最高:2%;
背景色:红色;
字号:18px;
}
.zcwf_lbltopbotom.zcwf_ckbox{
浮动:左;
}
提交您的数据即表示您同意按照我们的隐私政策进行传输、存储或处理。
功能启用提交按钮(termsCheckBox){
//如果已选中该复选框
如果(termsCheckBox.checked){
//将disabled属性设置为FALSE并启用按钮。
document.getElementById(“formsubmit”).disabled=false;
}
否则{
//否则,请禁用“提交”按钮。
document.getElementById(“formsubmit”).disabled=true;
}
}
尝试将脚本放在刚刚尝试的表单标记之外;不,不幸的是,这没有改变任何东西,按钮仍然被禁用,无论是否勾选复选框:-(如果您的
标记有语法错误,但您已剔除了输出,因此无法删除,则可能会发生这种情况。)see@tim如果我删除它,按钮从一开始就显示为已启用。我希望它从一开始就显示为已禁用。或者,有没有办法仅通过该功能来实现这一点?它应该可以正常工作