1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <title>Index</title>5 </Head>6 <Body>7 <formname= "MyForm"ID= "MyForm"Target= "_self"> 8Account:<inputtype= "text"name= "username"><BR>9Password:<inputtype= "Password"name= "Password"><BR>Ten <inputtype= "Submit"value= "Login"name= "Login"onclick= "Login ()" > One <inputtype= "Submit"value= "Register"name= "Register"onclick= "register ()" > A </form> - - <Scripttype= "Text/javascript"> the functionRegister () { - Alert ("Register") - document.getElementById ("MyForm"). Action="/register"; - document.getElementById ("MyForm"). Submit (); + } - functionLogin () { + Alert ("Login") A document.getElementById ("MyForm"). Action="/login"; at document.getElementById ("MyForm"). Submit (); - } - </Script> - - </Body> - </HTML>
Failure Codes
When writing the foreground JS, theID and function name can not be consistent, otherwise it will cause the onclick invalidation, modify the function name, problem solving!
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <title>Index</title>5 </Head>6 <Body>7 <formname= "MyForm"ID= "MyForm"Target= "_self"> 8Account:<inputtype= "text"name= "username"><BR>9Password:<inputtype= "Password"name= "Password"><BR>Ten <inputtype= "Submit"value= "Login"name= "Login"onclick= "Funlogin ()" > One <inputtype= "Submit"value= "Register"name= "Register"onclick= "Funregister ()" > A </form> - - <Scripttype= "Text/javascript"> the functionFunregister () { - Alert ("Register") - document.getElementById ("MyForm"). Action="/register"; - document.getElementById ("MyForm"). Submit (); + } - functionFunlogin () { + Alert ("Login") A document.getElementById ("MyForm"). Action="/login"; at document.getElementById ("MyForm"). Submit (); - } - </Script> - - </Body> - </HTML>
the modified Code
Input foreground JavaScript fails