简体   繁体   English

如何解决“未定义” JavaScript错误?

[英]How do I resolve JavaScript error “not defined”?

This form works in Safari. 此表单可在Safari中使用。 In IE, it mostly works, but I get an error "Object doesn't support this property or method." 在IE中,它通常可以正常工作,但是出现错误“对象不支持此属性或方法”。 on line 240. 在第240行。

In Firefox, no alert box appears, but the following error appears in the error console: 在Firefox中,没有出现警告框,但错误控制台中出现以下错误:

Error: myform is not defined Line: 240 (line 240 is below, starting with the word if) 错误:未定义myform行:240(下面是第240行,以单词if开头)

<script type="text/javascript">
// Validate the form
// Confirm with the visitor the amount he entered is correct
// Submit if OK is pressed
$(document).ready(function() {
    $("#myform").validate({
        submitHandler:function(form){
            if(confirm("Please confirm your donation of $"+ myform.x_Amount.value + " to us.")){
                form.submit();
            }
        }
    });
});

// Put grey "no spaces" example text in the credit card number field
$('#x_Card_Num').example('(NoSpaces)', {
  className: 'greydefaulttext'
});
</script>

Guess I need to define myform.x_Amount.value. 猜猜我需要定义myform.x_Amount.value。 Have tried doing this in various ways but haven't stumbled across the right location to define it yet, or even the right syntax. 尝试过以各种方式执行此操作,但尚未偶然找到正确的位置来定义它,甚至没有正确的语法。 Thanks for any help. 谢谢你的帮助。

Update: Thanks to fresh eyes from RC and Bobince, it was simply a typo: myform.x_Amount.value should be named form.x_Amount.value - it now works in all browsers. 更新:由于RC和Bobince的崭新眼光,这只是一个错字:myform.x_Amount.value应该命名为form.x_Amount.value-现在它在所有浏览器中都可以使用。

"submit is not a function" means that you named your submit button or some other element submit. “提交不是功能”表示您将提交按钮或其他元素命名为提交。 Rename the button to btnSubmit and your call will magically work. 将按钮重命名为btnSubmit,您的呼叫将神奇地工作。

When you name the button submit, you override the submit() function on the form. 当您将按钮命名为Submit时,您将覆盖表单上的commit()函数。

source 资源

that fixes your one error. 可以解决您的一个错误。 If by form.x_Amount.value you want to get the value of a textfield, try it like this: 如果要通过form.x_Amount.value获取文本字段的值,请尝试如下操作:

document.form_name.element_name.value;

tutorial 教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何解决:ReferenceError:未定义WebAssembly - How do I resolve: ReferenceError: WebAssembly is not defined 如何使用javascript中的regexp解决“无效量词”错误? - How do I resolve an “invalid quantifier” error with regexp in javascript? 如何解决此“未定义函数” JavaScript错误? - How do I resolve this “Undefined function” JavaScript Error? 如何解决“未定义 Firebase”错误? 我正在尝试在最基本的级别设置 Firebase - How do I resolve a "firebase is not defined" error? I'm trying to set up Firebase at the most basic level “未捕获的ReferenceError:未定义createDayLabel”-如何解决此错误以使Materialize的日期选择器正常工作? - “Uncaught ReferenceError: createDayLabel is not defined” - How do I resolve this error to get Materialize's date picker to work? 未捕获的ReferenceError:未定义IndexRoute-如何解决此错误以在react-router中使用IndexRoute? - Uncaught ReferenceError: IndexRoute is not defined - How do I resolve this error to use IndexRoute in react-router? 如何解决无限的Javascript承诺? - How do I resolve an infinite Javascript promise? 如何解决“模块未定义”错误? - How to resolve the “module is not defined” error? 如何在JavaScript中定义未定义? - How do I defined undefined in JavaScript? appmaker不匹配错误,我该如何解决? - appmaker mismatch error, how do i resolve?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM