62-js-表单验证及多选框

 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Lesson1</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	
	<style type="text/css">
		.info{font-size: 5px; color: red;}
	</style>
	
	<script type="text/javascript">
		// 检查中账号内容是否合法
		function checkAccount(){
			var account=document.getElementById("account").value.trim();
			if(account == ""){
				document.getElementById("account1").innerHTML = "账号不能为空";				
				document.getElementById("account1").className = "infor";		
				return false;
			}
			else{
				if(account.length>=7){
					console.log(account.substring(0,6));
					return false
				}
				else{
					document.getElementById("account1").innerHTML = "长度不够!";				
					document.getElementById("account1").className = "infor";	
					return false;
				}
			}
		}
		
		
		function check(){
			if(checkAccount()){
				
				return true;
			}
			else{
				return false;
			}
			
		}
	</script>
	
	
  </head>
  
  <body>
    This is my JSP page. <br> 
    
    <!-- 有序表 -->
    <ol type = "A">
    	<li>one</li>
    	<li>one</li>
    	<li>one</li>
    </ol>
    
    <!--  表格 跨行 -->
    <table border="3" width="600px" height="100px">
    	<tr><td rowspan="2">1</td><td>2</td><td>3</td><td>4</td></tr>
    	<tr> <td colspan="3">7</td></tr>
    </table>
    
    <form action="" method = "get" onsubmit="return check();">
	    <table>
	    	<tr><td>账号:</td> <td><input type="text" id="account" name="account" onblur="checkAccount();"></td> 
	    		<td><span id = "account1">请输入账号</span></td> 
	    	</tr>
	    	<tr>
	    		<td><input type="submit"></td>
	    	</tr>
	    </table>
	</form>    
    
    
  </body>
</html>

 


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript">
		// 全选控制
		function check(){
			var box=document.getElementsByName("ids"); // 取到元素节点信息
			if(box[0].checked){
				for(var i = 1; i < box.length; i++){
					box[i].checked = true;
				}
				document.getElementById("btn").disabled="";
			}
			else{
				for(var i = 1; i < box.length; i++){
					box[i].checked = false;
				}
				document.getElementById("btn").disabled="disabled";
			}
		}
		
		// 单选控制
		function check1(){
			var box=document.getElementsByName("ids"); // 取到元素节点信息
			var str = false;
			for(var i = 1; i < box.length; i++){
				if(box[i].checked == false){
					str = true; // 至少有一个没选
					break;
				}
			}
			//alert(str);
			if(str){
				box[0].checked = false;
				document.getElementById("btn").disabled="disabled";
			}
			else{
				box[0].checked = true;
				document.getElementById("btn").disabled="";
			}
			// 单独判断是否有一个元素被选中的状态
			var str1 = false;
			for(var i = 1; i < box.length; i++){
				str1 = true;
				break;
			}
			//alert(str1);
			if(str1){
				document.getElementById("btn").disabled="";
			}
			else{
				document.getElementById("btn").disabled="disabled";
			}
		}
		// 执行删除元素
		function del(){
			var box=document.getElementsByName("ids"); // 取到元素节点信息
			var ids="";
			for(var i = 1; i < box.length; i++){
				if(box[i].checked){
					ids += box[i].value+",";
				}
			}
			if(ids == ""){
				alert("请选择需要删除的对象!");
				document.getElementById("btn").disabled="disabled";
				return false;
			}
			if(confirm('你确定要删除'+ids+'的数据吗?')){
				//执行删除
				alert(ids);
			}
			else{
				alert('取消了删除!');
			}
		}
	
	</script>
	
	
  </head>
  
  <body>
    <table width="400" height="100" border="2">
    	<tr><td><input type="checkbox" name="ids" onclick="check();"></td><td>姓名</td></tr>
    	<tr><td><input type="checkbox" name="ids" value="1" onclick="check1();"></td><td>姓名1</td></tr>
    	<tr><td><input type="checkbox" name="ids" value="2" onclick="check1();"></td><td>姓名2</td></tr>
    	<tr><td><input type="checkbox" name="ids" value="3" onclick="check1();"></td><td>姓名3</td></tr>
   		<tr><td colspan="2"><input type="button" value="删除" onclick="del();" id = "btn" disabled="disabled"></td></tr>
    </table>
  </body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ystraw_ah

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值