<html>
<body>
<form action="/demo/htmldom/action_page.php">
选择文件:<input type="file" id="myFile" name="usr_file" required>
<input type="submit">
</form>
<p>请点击“试一试”按钮,查看是否必须在提交表单前在文件上传字段中选取文件。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myFile").required;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>