这是一个我将要上传图片的页面,但当我在javascript中按ID选择元素时,浏览器会说“无法设置proprety" onchange" of null'但我写的完全相同的ID请帮助这是我的代码
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<link href='http://fonts.googleapis.com/css?family=Arvo:400,700|Ubuntu:300,400,500,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
<script>
function _(id){
return document.getElementById(id);
}
_("file_upload").onchange = function() {
alert("It works!"); };
</script>
</head>
<body>
<div id="container">
<div id="half1">
<div id="upload">
<div id="user">
<img src="/img/1.png" alt="User image"/>
</div>
<img src="/img/plus.png" alt="Upload" />
<input type="file" id="file_upload"/>
</div>
</div>
</div>
</body>