我有一个调用 Javascript 函数的简单 html 页面。
由于某种原因,没有调用 JS 函数
<html>
<body>
function validateForm()
{
alter("Validate form")
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
}
<form name="myForm" onsubmit="validateForm()">
First name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body>
最终的js函数..
<html>
<head>
<script type="text/javascript">
function validateForm()
{
alter("Validate form")
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
}
}
</script>
<body>
<form name="myForm" onsubmit="validateForm()">
First name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body>