zoukankan      html  css  js  c++  java
  • js练习 表单非空验证 省级联动 输出最大值

    js 用户填写非空验证

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    	</head>
    	<body>
    		<form action="index.html" method="get" onsubmit="return checkLogin()">
    			
    			<p>用户名<input type="text" id="tv_uname"/><span id="tv_uname_span"></span></p>
    			<p>密码<input type="password" id="tv_upsw"/><span id="tv_upsw_span"></span></p>
    			<p><input type="submit" value="提交"/></p>
    		</form>
    		<script type="text/javascript">
    			
    			function checkLogin(){
    				document.getElementById("tv_uname_span").innerHTML="";
    				document.getElementById("tv_upsw_span").innerHTML="";
    				
    				var name = document.getElementById("tv_uname").value;
    				if(name==null||name==""){
    					document.getElementById("tv_uname_span").innerHTML="用户名不能空";
    					return false;
    				}
    				var psw = document.getElementById("tv_upsw").value;
    				if(psw==null||psw==""){
    					document.getElementById("tv_upsw_span").innerHTML="密码不能空";
    					return false;
    				}
    				return true;
    			}
    		</script>
    	</body>
    </html>
    

    js 省级联动

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    	</head>
    	<body>
    		<select onchange="show(this.value)">
    			<!--this.value就是index,也就是当前的value-->
    			<option value="0">北京市</option>
    			<option value="1">长沙市</option>
    			<option value="2">郴州市</option>
    		</select>
    		<select id="tv_select">
    			
    		</select>
    		<script type="text/javascript">
    			
    			var num = [["一区","二区","三区"],["4区","5区","6区"],["7区","8区","9区"]];
    			var select = document.getElementById("tv_select");
    //			select等于节点
    			function show(index){
    				var citys = num[index];
    //				citys等于三个区
    				var temp = "";
    				for(var i=0;i<citys.length;i++){
    					temp+="<option>"+citys[i]+"</option>";
    //					三个区都在
    				}
    				select.innerHTML=temp;
    //				三个区赋值给节点
    			}
    		</script>
    		
    	</body>
    </html>
    

    js 输出最大值

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    	</head>
    	<body>
    		<form>
    			<p>数值1 <input type="text" class="s"</p>	
    			<p>数值2 <input type="text" class="s"</p>
    			<p>数值3 <input type="text" class="s"</p>
    			<p>最大值 <input type="text" id="max"</p>
    			<p><input type="button" value="计算最大值" onclick="show()"</p>	
    		</form>
    		
    		<script type="text/javascript">
    			var sum = document.getElementsByClassName("s");
    			var temp = sum[0].value;
    			function show(){
    				for(var i=0;i<sum.length;i++){
    					if(temp<sum[i].value){
    						temp=sum[i].value;
    					}
    				}
    				document.getElementById("max").value=temp;
    			}
    		</script>
    	</body>
    </html>
    

  • 相关阅读:
    mysql 触发器
    Yii 1.0 基础
    python解释执行原理(转载)
    python中使用selenium调用Firefox缺少geckodriver解决方法
    Python中os和shutil模块实用方法集锦
    pytesseract使用
    anaconda安装第三方库
    anaconda spyder异常如何重新启动
    windows下python3.6 32bit 安装django
    设置SO_RECVBUF和SO_SENDBUF套接字选项
  • 原文地址:https://www.cnblogs.com/ynzj123/p/13403034.html
Copyright © 2011-2022 走看看