<!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 />
  密 &nbsp; 码:
  <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文件的方法是报错 这是什么原因???

解决方案 »

  1.   

    报什么错?
    你js方法外面包
    <script></script>了吗?
    另外 你吧 input 的type="button" 看看?
    是不是因为页面提交的问题
      

  2.   

    <!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>
    <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 />
      密 &nbsp; 码:
      <input type="text" name="password" id="password" /><br>
       <input type="button" name="submit1" id="submit1"  value="提交" onclick="yanzheng()"/>
    </form>
    </body>
    </html>
      

  3.   

    <!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>
    <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 />
      密 &nbsp; 码:
      <input type="text" name="password" id="password" /><br>
       <input type="button" name="submit1" id="submit1"  value="提交"/>
    </form>
    </body>
    </html>
      

  4.   

    你写错了吧
    src = "js.js"
      

  5.   

    很明显是写错了,应该是src,不是scr
      

  6.   

    js文件引用出问题了
    以后注意从正确的地方拷贝,改一下引用路径就OK了。
    加油!
    <script type="text/javascript" src="js.js"></script>
      

  7.   

    第一眼就发现那是SCR了 ......
      

  8.   

    正解,将 scr 改为 src 即可