实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <input type="text" id="inp" value="明天我们要有好的心情才可以学到更多的知识,但是我发现最近深圳校区你们军哥变帅了!"><br/> <select name="" id="" onchange="check()"> <option value="">南宁</option> <option value="">广州</option> <option value="">深圳</option> <option value="">郑州</option> </select> <input type="radio" name="sex" value="0" onchange="check()">女 <input type="radio" name="sex" value="1" onchange="check()">男 <input type="radio" name="sex" value="2" onchange="check()">保密 <input type="radio" name="sex" value="3" onchange="check()">旺儒 <input type="checkbox" name="lovegood" value="0" onchange="check()" >打豆豆<br/> <form action="http://www.baidu.com" method="post" onsubmit="return test()" onreset="return confirm('你确定要重置吗')"> <input type="text" name="username" id="username" onblur="user()"><br/> <input type="password" name="password" id="pwd" onblur="zzz()"><br/> <input type="submit"> <input type="reset"> </form> </body> <script> // var bool = confirm('你确定要重置吗'); // alert(bool); var inp = document.getElementById('inp'); var username = document.getElementById('username'); var pwd = document.getElementById('pwd'); //选中事件 inp.onselect = function(){ alert('你选中了文本'); } function check(){ alert('改变了选项') } function user(){ var str = username.value; if(str.match(/^\w{4,8}$/) == null){ return false; }else{ return true; } } function zzz(){ var pstr = pwd.value; if(pstr.length >= 6){ return true; }else{ return false; } } function test(){ return user()&&zzz(); } </script> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例