<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- <script>-->
<!-- alert("hello javascript")-->
<!-- </script>-->
</head>
<body>
<div id="father">
<span>
用户名:<input type="text" name="=username">
</span>
<input type="radio" name="check" value="boy" id="boy">boy
<input type="radio" name="check" value="girl" id="girl">girl
</ul>
</div>
<script>
username=document.getElementsByName("username");
//获得值
username.value;
//修改值
username.value="hello"
boy_radio=document.getElementById("boy")
girl_radio=document.getElementById("girl")
//boy_radio.checked boy_radio如果被选中了就返回true,否则返回false。通过设置 boy_radio.checked=true;使得boy_radio被选中
boy_radio.checked=true;
</script>
</body>
</html>
onsubmit &onclick
<form action="https://www.baidu.com/" method="post" onsubmit="return a()">
<span>用户名: <input type="text"name="username"> </span>
<span>密码: <input type="password" name="password"> </span>
<button type="submit" onclick="aa()">提交</button>
</form>
<script>
function a(){
alert(1);
return true;
}
function aa(){
alert(2);
}
</script>
onsubmit 绑定a()函数,在提交表单数据之前会调用a()函数如果返回的是true就提交,false就阻止
onclick 绑定aa(),单击按钮aa()函数执行