var img = new Image(); img.onload = function(){ document.write(img.width);}img.src = "test.jpg"; 试试这样
把函数写在body的onload事件里面呢