• 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>
    

  • 相关阅读:
    python 发送带有附件的邮件
    【转】python的定时任务
    git 日常命令
    go之基础语法等相关内容-148
    redis集群等相关内容-147
    redis高级部分等相关内容-146
    sqlachemy之增删改查等相关内容-145
    flask之wtforms、信号、sqlalchemy等相关内容-144
    flask之上下文源码、flask-session、数据库连接池、flask-script等相关内容-143
    flask之中间件、蓝图、请求上下文等相关内容-142
  • 原文地址:https://www.cnblogs.com/ynzj123/p/13403034.html
Copyright © 2020-2023  润新知