编辑下面的代码:【加编码】
<html> <body> <form action="form_action.asp"> 名: <input type="text" id="myText" name="fname"> <input type="submit"> </form> <p>点击 "点我" 按钮为文本域设置 required 属性。</p> <p><strong>提示:</strong> 在点击“点我”按钮后点击 "Submit" 按钮查看效果。</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myText").required = true; document.getElementById("demo").innerHTML = " required 属性已设置。文本域在表单提交时是必填字段。"; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂