javascript--Cancel the Submit submission default behavior for a tag and form

Source: Internet
Author: User

1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title>Title</title>6<script>7         /**8 * Cancel Browser default behavior9 * such as:Ten * A link jump, One * Submit button Submission Form A * (PS: Right-click popup menu also) - * Implementation method: - * Event.preventdefault (); the * return false; -          * -          * */ -Window.onload =function () { +             varlink = document.getElementById (' link '); -             varCheck = document.getElementById ("Check"); +             //form element Get A             varInputtexts = Document.queryselectorall ("[type= ' text ']"); atLink.onclick =function () { -                 //Cancel Browser default behavior -                 //Event.preventdefault (); -                 return false; -             } -  in             //Prevent right-click popup menu -Document.oncontextmenu =function () { to                 return false; +             } -  theCheck.onclick =function () { * Event.preventdefault (); $                 if(Inputtexts[0].value.indexof (' username ')! =-1) {Panax NotoginsengConsole.log ("Login Successful! Please jump to page ~ "); -}Else{ theConsole.log ("Login failed! Please re-recharge ~ "); +                 } A             } the  +  -         } $</script> $ -<body> -<form action= "http://www.baidu.com" > the<!--form submission, often have to verify the data first, so the default commit behavior is canceled, the data through the detection of legal, with JS implementation of data submitted-- -<input type= "text" value= "I am username!!" name= "username" >Wuyi<input type= "Submit" value= "Commit" id= "check"/> the</form> -<a href= "http://www.baidu.com" >a link tag has default behavior </a> Wu<a href= "#" >a link tag has default behavior </a> -<a href= "Javascrit:;" >a link tags have default behavior </a> About<a href= "http://www.baidu.com" id= "link" >a link tag has default behavior </a> $</body> -

javascript--Cancel the Submit submission default behavior for a tag and form

Related Article

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.