未捕获的类型错误:不能读取属性'null - error在Chrome
Uncaught TypeError: Cannot read property 'value' of null - error in Chrome
html部分为:
<html:file property="claimUploadFile" id="claimUploadFile" size="50" />
Javascript部分是:
if(document.getElementById("claimUploadFile").value == ""){
var messagePrompt = 'Some message';
alert(messagePrompt);
return;
}
以上代码在IE中工作正常,但在Chrome中给出错误"Uncaught TypeError: Cannot read property 'value' of null" .
我认为html:file是错误的,你的代码中也没有函数,所以你不能使用返回语句
<form name="fileUpload">
<input type="file" name="claimUploadFile" value="claimUploadFile" id="claimUploadFile">
</form>
Js部分 var file = document.forms['fileUpload']['claimUploadFile'].files[0];
//file.name == "somepic.png"
//file.type == "image/png"
//file.size == 254845
if(file == undefined){
var messagePrompt = 'Some message';
alert(messagePrompt);
}
或
document.getElementById('claimUploadFile').files[0] // Does the same work
查看演示:https://jsbin.com/rodano/4/edit?html,js,console,output
相关文章:
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- 未捕获的类型错误:无法调用方法'shift'Chrome中的Facebook JS库为null
- 当JS在Chrome控制台上正常工作时,Selenium JavaScript执行器返回null
- chrome和firefox上的javascript null比较不同
- 为什么chrome.debugger.attach 回调函数应该像cb.bind(null,..)一样使用
- 错误:“null”为空或不是IE8中的对象,而不是Chrome或Firefox
- 无法在Chrome的Javascript控制台中读取null的属性“style”
- Chrome,Safari - 未捕获的类型错误:无法读取 null 的属性“状态”
- 对象属性在 chrome.storage.sync.set 之后变为 null
- Chrome javascript错误无法读取属性'开启器'为null
- 使用chrome fileSystem编写时,字符串中的Javascript NULL字符
- 在Chrome下,Mootools注入失败,元素为null
- 在Chrome中,Access-Control-Allow-Origin不允许为null.加载JSON
- 窗口.getSelection在Chrome上返回null
- getSVGDocument在Chrome中返回NULL
- 未捕获的类型错误:不能读取属性'null - error在Chrome
- CKEDITOR.replace(elm[0])在Chrome上返回null
- Javascript在Chrome返回null, HTML元素在源
- getSVGDocument在FireFox和Chrome中返回null
- LocalStorage在chrome中的不同选项卡返回null