This is now possible with HTML5's File API:
<script>
var myFile = document.getElementById('myFile');
var size;
myFile.addEventListener('change', function() {
size = this.files[0].size;
});
</script>
This is supported by most of the latest browsers.
Internet Explorer supports this workaround involving ActiveX, but it requires lowering Internet Explorer's security settings, so it isn't really an option for most applications.
It takes more work, but use a Flash-based uploader such as SWFUpload if you really need to do this in IE9 or below. IE10 will (hopefully) add support for the HTML5 File API.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…