日期:2014-05-16 浏览次数:20439 次
<input type="text" size="4" value="10" name="fileSizeLimit" id="fileSizeLimit"/> K <input type="file" name="file1" id="file1" size="40" onchange="changeSrc(this)"/> <img src="about:blank" id="fileChecker" alt="test" height="18"/> <script type="text/javascript"> var oFileChecker = document.getElementById("fileChecker"); function changeSrc(filePicker) { oFileChecker.src = filePicker.value; } oFileChecker.onreadystatechange = function () { if (oFileChecker.readyState == "complete") { checkSize(); } } function checkSize() { var limit = document.getElementById("fileSizeLimit").value * 1024; if (oFileChecker.fileSize > limit) { alert("too large"); } else { alert("ok"); } } </script>
<img src="monkey.gif" id="monkey" alt="monkey" /> loops: <span id="loopsNum"></span> <script type="text/javascript"> var loops = 0; document.getElementById("monkey").onload = function () { document.getElementById("loopsNum").innerText= loops; loops ++; } </script>
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />