<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" scr="js.js"></script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
用户名:<input type="text" name="names" id="names" />
<br />
密 码:
<input type="text" name="password" id="password" /><br>
<input type="button" name="submit1" id="submit1" value="提交" onclick="yanzheng()"/>
</form>
</body>
</html>
js.js文件function yanzheng(){
alert("用户名不能为空!")
}
<input type="button" name="submit1" id="submit1" value="提交" onclick="yanzheng()"/>
这里调用js文件的方法是报错 这是什么原因???
你js方法外面包
<script></script>了吗?
另外 你吧 input 的type="button" 看看?
是不是因为页面提交的问题
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" scr="js.js"></script>
</head>
<script type="text/javascript">
function yanzheng() {
if (form1.names.value=="") {
alert("用户编号不能为空!");
return false;
};
return true;
};
</script>
<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return yanzheng();">
用户名:<input type="text" name="names" id="names" />
<br />
密 码:
<input type="text" name="password" id="password" /><br>
<input type="button" name="submit1" id="submit1" value="提交" onclick="yanzheng()"/>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" scr="js.js"></script>
</head>
<script type="text/javascript">
function yanzheng() {
if (form1.names.value=="") {
alert("用户名不能为空!")
return false;
};
return true;
};
</script>
<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return yanzheng();">
用户名:<input type="text" name="names" id="names" />
<br />
密 码:
<input type="text" name="password" id="password" /><br>
<input type="button" name="submit1" id="submit1" value="提交"/>
</form>
</body>
</html>
src = "js.js"
以后注意从正确的地方拷贝,改一下引用路径就OK了。
加油!
<script type="text/javascript" src="js.js"></script>