<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form action="post"> <p> <span>用户名</span><input type="text"id="username"> </p> <script> var inputvalue=document.getElementById("username"); </script> </form> </body> </html>
获得表单的值
修改表单的值
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form action="post"> <p> <span>性别</span> <input type="radio" name="sex" value="male"id="id1">男 <input type="radio" name="sex" value="female"id="id2">女 </p> <script> var boy=document.getElementById("id1"); var girl=document.getElementById("id2"); </script> </form> </body> </html>
对于单选框和多选框,value已经确定的元素的时候,获得该元素的值要用checked进行检查,