jquery 登陆

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>文本框输入值文字消失</title>
<script type="text/jscript" src="../jqueryjs/jquery-1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

			$("#focus .input_txt").each(function(){
					var thisVal=$(this).val();
					//判断文本框的值是否为空,有值的情况就隐藏提示语,没有值就显示
					if(thisVal!=""){
							$(this).siblings("span").hide();
						}else{
							$(this).siblings("span").show();
						}
					//聚焦型输入框验证	
					$(this).focus(function(){
							$(this).siblings("span").hide();
						}).blur(function(){
								var val=$(this).val();
								if(val!=""){
									$(this).siblings("span").hide();
								}else{
									$(this).siblings("span").show();
								}	
						});
				})
				$("#keydown .input_txt").each(function(){
					var thisVal=$(this).val();
					//判断文本框的值是否为空,有值的情况就隐藏提示语,没有值就显示
					if(thisVal!=""){
							$(this).siblings("span").hide();
						}else{
							$(this).siblings("span").show();
						}
						$(this).keyup(function(){
							var val=$(this).val();
							$(this).siblings("span").hide();
						}).blur(function(){
								var val=$(this).val();
								if(val!=""){
									$(this).siblings("span").hide();
								}else{
									$(this).siblings("span").show();
								}
							})
					})	
		})
</script>
<style type="text/css">
	form{width:400px;margin:10px auto;border:solid 1px #E0DEDE;background:#FCF9EF;padding:30px;box-shadow:0 1px 10px rgba(0,0,0,0.1) inset;}
	label{display:block;height:40px;position:relative;margin:20px 0;}
	span{position:absolute;float:left;line-height:40px;left:10px;color:#BCBCBC;cursor:text;}
	.input_txt{width:398px;border:solid 1px #ccc;box-shadow:0 1px 10px rgba(0,0,0,0.1) inset;height:38px;text-indent:10px;}
	.input_txt:focus{box-shadow:0 0 4px rgba(255,153,164,0.8);border:solid 1px #B00000;}
	.border_radius{border-radius:5px;color:#B00000;}
	h2{font-family:"微软雅黑";text-shadow:1px 1px 3px #fff;}
</style>
</head>
<body>
<form class="border_radius" id="focus">
        <h2>聚焦型提示语消失</h2>
        <label><span>花瓣注册邮箱</span><input type="text" class="input_txt border_radius"  /></label>
        <label><span>密码</span><input type="text" class="input_txt border_radius" /></label>
    </form>
	<form class="border_radius" id="keydown">
    	<h2>输入型提示语消失</h2>
    	<label><span>花瓣注册邮箱</span><input type="text" class="input_txt border_radius"  /></label>
        <label><span>密码</span><input type="text" class="input_txt border_radius" /></label>
</form>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jQuery是一个轻量级的JavaScript库,它简化了HTML文档遍历、事件处理、动画和Ajax交互等常见的Web开发任务。在实现登录注册功能时,jQuery主要是用来处理DOM操作和用户交互,而数据的验证和后端通信通常会涉及到服务器端语言(如PHP、Node.js等)。 使用jQuery实现登录注册的基本步骤: 1. **HTML结构**:创建登录/注册表单,包括输入框、密码输入框、提交按钮等元素。 ```html <form id="loginForm"> <input type="text" name="username" placeholder="用户名"> <input type="password" name="password" placeholder="密码"> <button type="submit">登录</button> </form> <form id="registerForm"> <!-- ...类似用户名、密码、确认密码等字段 --> <button type="submit">注册</button> </form> ``` 2. **jQuery绑定事件**:使用`.on()`方法为表单绑定提交事件,防止表单默认提交,同时处理验证和提交逻辑。 ```javascript $(document).ready(function() { $('#loginForm, #registerForm').on('submit', function(e) { e.preventDefault(); // 阻止表单默认提交 // 进行表单验证,如为空或不符合规则 if (validateForm()) { // 提交数据到服务器(通常是AJAX请求) sendFormData($(this)); } }); }); ``` 3. **验证函数**:根据实际需求编写验证函数,检查用户输入是否合法。 ```javascript function validateForm() { // 示例:检查用户名和密码是否为空 var username = $('#username').val(); var password = $('#password').val(); if (username === '' || password === '') { alert('请输入完整信息'); return false; } // 更复杂的验证规则可以添加在这里 return true; } function sendFormData(form) { var formData = form.serialize(); $.ajax({ type: 'POST', url: '/api/login/register', // 后端接口地址 data: formData, success: function(response) { console.log(response); }, error: function(xhr, status, error) { console.error(error); } }); } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值