<script>
function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if (x == "") {
alert("必须填写姓名!");
return false;
}
}
</script>
</head>
<body>
<form name="myForm" action="/demo/action_page.php" onsubmit="return validateForm()" method="post">
姓名:<input type="text" name="fname">
<input type="submit" value="提交">
</form>