简单教程
提交运行
代码编辑器:
<form action="/dy/html/getpost"> 周: <input type="week" id="myWeek" name="week_year"> <input type="submit"> </form> <p>点击 "点我" 按钮设置 week 字段的 required 属性</p> <p><strong>提示:</strong> 在点击 “点我” 按钮前后点击 "提交" 按钮查看效果</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myWeek").required = true; document.getElementById("demo").innerHTML = "required 属性已设置。表单提交前 week 字段为必填字段。"; } </script>
运行结果: