This is a very pit of the problem, the reason is that <script> is the HTML tag, can not be written into the JS file, the following gives a simple HTML call JS example, hope to encounter this problem friends can solve
JS file content:
function Check () {
if (form1.user.value== "") {
Alert ("Please enter user name");
Form1.user.focus ();
Return
}
else if (form1.pwd.value== "") {
Alert ("Please enter a password");
Form1.pwd.focus ();
Return
}
else{
Form1.submit ();
}
}
HTML content:
<meta name= "Generator"
Content= "HTML Tidy for HTML5 (experimental) for Windows https://github.com/w3c/tidy-html5/tree/c63cc39"/>
<title>html+js</title>
<body>
<script language= "JavaScript" src= ' testscript.js ' >
</script>
<form name= "Form1" method= "Post" action= "" >
User name: <input name= "User" type= "text" id= "user" >
Password: <input name= "pwd" type= "text" id= "pwd" >
<input name= "button" type= "button" class= "Btn_grey" value= "Login" onclick= "check ()" >
<input name= "Submit2" type= "reset" class= "Btn_grey" value= "reset" >
</form>
</body>
The effect is as follows: The function is to determine whether the input box is empty, empty pop-up prompt language