Why do you write JavaScript code in HTML directly, but not by calling JS files?

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.