<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form name="myForm" action="" method="post" onsubmit="return dateForm()">
Name:<input type="text" name="fname" />
<input type="submit" name="Sub"/>
</form>
<p id="p1">
hello world
</p>
<input type="button" value="Hidden" onclick="btnFun()" />
<script>
//对表单数据验证
function dateForm(){
let x=document.forms["myForm"]["fname"].value;
if(x==""){
console.log("kong");
return false;
}
}
//改变CSS
document.getElementById("p1").style.color="blue";
//隐藏文本
function btnFun(){
document.getElementById("p1").style.visibility="hidden";
}
</script>
</body>
</html>