oninput事件(检测用户的输入内容)

<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="utf-8">
    <title></title>
    <style>
        .search{
            position: relative;
            width:390px;
            height:30px;
            border:1px solid #ccc;
        }
        .search input{
            width:380px;
            height:25px;
        }
        .search label{
            position: absolute;
            top:0;
            left:40px;
            color:#848181;
            cursor:text;/*鼠标光标 文本显示*/
        }
    </style>
</head>


<body>
    <div class="search">
        <input id="txt" type="text">
        <label id="hotMessage"for="txt">必败的国际大牌</label>
    </div>
</body>
</html>




<script>
    var hotMessage = document.getElementById("hotMessage");
    var txt = document.getElementById("txt");
    //oninput事件是表单的输入事件,用来获取表单的输入信息
    txt.oninput = function (){
        if(this.value!=""){
            hotMessage.style.display = "none";
        }else{
            hotMessage.style.display = "inline-block";
        }
    }
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
regedit.jsp <%@ page contentType="text/html;charset=UTF-8"%> <script language="javascript"> function on_submit() { if (form1.username.value == "") { alert("用户名不能为空,请输入用户名!"); form1.username.focus(); return false; } if (form1.userpassword.value == "") { alert("用户密码不能为空,请输入密码!"); form1.userpassword.focus(); return false; } if (form1.userpassword2.value == "") { alert("用户确认密码不能为空,请输入密码!"); form1.userpassword2.focus(); return false; } if (form1.userpassword.value != form1.userpassword2.value) { alert("密码与确认密码不同"); form1.userpassword.focus(); return false; } } </script> <script language="javascript"> function check(action) { form1.action=action; form1.submit(); if (form1.username.value == "") { alert("用户名不能为空,请输入用户名!"); window.location.href="regedit.jsp"; } } </script> <html> <head> <title>无标题文档</title> </head> <body> <form name="form1" method="post" action="regeditIn.jsp" onSubmit="return on_submit()"> 用户名: <input type="text" name="username"/> <input type="button" name="Button" value="检测用户" onClick="check('checkuser.jsp')"> <p>密码: <input type="password" name="userpassword"/> </p> <p>确认密码: <input type="password" name="userpassword2"/> </p> <p> <select name="selectlogrole"> <option value="student">学生</option> <option value="teacher">老师</option> <option value="admin">管理员</option> </select> </p> <p align="left"> <input type="submit" name="Submit" value="提交"/> </p> </form> </body> </html> regeditIn.jsp <%@ page contentType="text/html;charset=UTF-8"%> <%@ page import="java.sql.*" %> <%@ page import="Bean.QueryBean" %> <jsp:useBean id="query" class="Bean.QueryBean" scope="session"> <jsp:setProperty name="query" property="*"/> </jsp:useBean> <html> <body> <% request.setCharacterEncoding("UTF-8"); String name=request.getParameter("username"); String password=request.getParameter("userpassword"); String s=request.getParameter("selectlogrole"); String str="select username from userinfo where username='"+name+"'"; ResultSet rs=query.executeQuery(str); if(rs.next()){ %> <script language="javascript"> alert("此用户已经被占用请重新注册"); history.back(); </script> <% }else{ String sql="insert into userinfo(username,userpassword,logrole) values('"+name+"','"+password+"','"+s+"')"; boolean sert=query.executeUpdata(sql); if(sert) {%> <script language="javascript"> alert("注册成功"); window.location.href="index.jsp"; </script> <% }else { %> <script language="javascript"> alert("注册失败!!"); history.back(); </script> <% } } %> </body> </html> checkuser.jsp <%@ page contentType="text/html;charset=UTF-8"%> <%@ page import="java.sql.*" %> <%@ page import="Bean.QueryBean" %> <jsp:useBean id="query" class="Bean.QueryBean" scope="session"> <jsp:setProperty name="query" property="*"/> </jsp:useBean> <html> <body> <% request.setCharacterEncoding("UTF-8"); String name=request.getParameter("username"); String str="select username from userinfo where username='"+name+"'"; ResultSet rs=query.executeQuery(str); if(rs.next()){ %> <script language="javascript"> alert("此用户已经被占用"); history.back(); </script> <% } else { %> <script language="javascript"> alert("此用户可用"); history.back(); </script> <% } %> </body> </html>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值