Javascript 对象在 IE 中为 null 或不是 object
Javascript object is null or not object in IE
我有一个表单,javascript在其中添加了复选框,当表单提交时,它会检查复选框是否已被选中。这在Firefox或Chrome中工作正常,但在IE7或8中,它会导致错误document.myform.mycheckbox.checked为null或不是对象。
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.name = "mycheckbox";
checkbox.value= 291;
var div = document.getElementById("addcb");
div.appendChild(checkbox);
checkbox.checked = false;
在表单标签中,我有onSubmit="return CheckForm();",它在Firefox或Chrome中工作正常,但在IE7或8中,它提交表单而不检查表单或其他表单对象。
if (document.myform.mycheckbox.checked == false){
errorMsg += "'n'tAgree 't- Please Click I Agree Checkbox";
}
//If there is aproblem with the form then display an error
if ((errorMsg != "") || (errorMsgLong != "")){
msg = "_______________________________________________________________'n'n";
msg += "The form has not been submitted because there are problem(s) with the form.'n";
msg += "Please correct the problem(s) and re-submit the form.'n";
msg += "_______________________________________________________________'n'n";
msg += "The following field(s) need to be corrected: -'n";
errorMsg += alert(msg + errorMsg + "'n" + errorMsgLong);
return false;
}
return true;
我使用开发人员工具创建了一个报告错误的 Brakpoint:
document.myform.mycheckbox.checked is null or not an object
在创建它时,也要给它一个 ID
checkbox.id = "mycheckbox";
然后要找到它,请执行
if (document.getElementById("mycheckbox").checked == false)
相关文章:
- delete在Object上效率低下,但在DOM Element's的数据属性,与null out相比
- 为什么是文档.旧版应用程序中的DOM-object.properties为null
- javascript对象显示为null,但object.properties返回数据
- Javascript Date() object with NULL Time
- Uncaught TypeError:对象原型在Symfony 2中只能是Object或ExtJS为null
- 在不使用object.Create的情况下创建具有null原型的javascript对象
- 为什么MDN Object.create polyfill上的Temp.prototype设置为null
- 预期 null({ }) 等于 Object({ })
- requireJS Object 原型可能只是一个 Object 或 null - jQuery
- Javascript 对象在 IE 中为 null 或不是 object
- return !!( proto === null || proto.constructor === Object );
- Use cases of Object.create(null)?
- 原型、Object.prototype和Object.create为Null
- 从什么时候开始 null.toString() 返回 [object Null]
- Are [object Null] &[object Undefined]有待实现
- 为什么typeof (null) == 'object'在JavaScript
- Javascript中的Object.create(null) &创建新的顶级对象
- 使用Object.create(null)而不是{}是不好的做法吗?
- 单元测试过滤器错误:预期null等于[object]
- 未捕获的类型错误:对象原型在ember.js上只能是Object或null