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