标签:
js 默认行为取消 可以简单的 return false; 看需求吧
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>事件编程</title> <script> //取消默认行为 function prevent(event) { if(window.event) { window.event.returnValue=false; } else { event.preventDefault(); } } window.onload = function(){ $(‘btnLogin‘).onclick = function(event){ if ($(‘username‘).value == ‘‘) { prevent(event); } } } </script> </head> <body> <form action=‘moren.php‘ method=‘post‘> 用户:<input id=‘username‘ name=‘username‘ type=‘text‘><hr>密码:<input name=‘password‘ type=‘password‘><hr><input type=‘submit‘ id=‘btnLogin‘ value=‘Login‘> </form> </body> </html>
标签:
原文地址:http://www.cnblogs.com/gyz418/p/5166405.html