zoukankan      html  css  js  c++  java
  • 1-4-JS基础-条件判断

    第一种

    1.if(条件成立){

    执行某件事
    }


    2.if(条件成立){
    执行某件事
    }else{
    执行另外一件事

    }

    3.if(条件1成立){
    执行某件事
    }else if(条件2成立){
    执行某件事
    }
    else if(条件3成立){
    执行某件事
    }
    else{
    执行某件
    }

    <!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>html属性操作</title>
    <style>
    #div1{ 300px; height:200px; border:1px solid #ccc; margin-bottom:20px}
    
    </style>
    <script>
    
    	
    window.onload = function(){
    	var oDiv = document.getElementById('div1');
    	var oText = document.getElementById('text1');
    	var oBtn1 = document.getElementById('btn1');
    	var oSpan = document.getElementById('span1');
    	oBtn1.onclick = function(){
    			if(oText.value==''){
    				alert('请输入点内容吧!');
    				}else{
    					oDiv.innerHTML+=oSpan.innerHTML + oText.value+"<br/>";
    			oText.value='';
    					}
    			
    		}
    	}
    </script>
    </head>
    
    <body>
    <div id="div1"></div>
    <span id="span1">你好:</span>
    <input type="text" id="text1"/>
    <input type="button" id="btn1" value="按钮" /> 
    </body>
    </html>
    
    <!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>html属性操作</title>
    <style>
    #div1 {
    	300px;
    	height:200px;
    	border:1px solid #ccc;
    	margin-bottom:20px
    }
    </style>
    <script>
    
    	
    window.onload = function(){
    	var oText = document.getElementById('text1');
    	var oBtn1 = document.getElementById('btn1');
    	oBtn1.onclick = function(){
    		if(oText.value==''){
    			alert('请输入口令');
    			
    			}else if(oText.value=='css'){
    				alert('你写的是css,恭喜通过!');
    				}
    				else if(oText.value=='html'){
    				alert('你写的是html,恭喜通过!');
    				}
    				else if(oText.value=='js'){
    				alert('你写的是js,恭喜通过!');
    				}
    				else{
    				alert('你的口令输入有误!');
    				}
    		}
    	}
    </script>
    </head>
    <body>
    <input type="text" id="text1"/>
    <input type="button" id="btn1" value="验证" />
    </body>
    </html>
    



  • 相关阅读:
    Codeforces 845E Fire in the City 线段树
    Codeforces 542D Superhero's Job dp (看题解)
    Codeforces 797F Mice and Holes dp
    Codeforces 408D Parcels dp (看题解)
    Codeforces 464D World of Darkraft
    Codeforces 215E Periodical Numbers 容斥原理
    Codeforces 285E Positions in Permutations dp + 容斥原理
    Codeforces 875E Delivery Club dp
    Codeforces 888F Connecting Vertices 区间dp (看题解)
    Codeforces 946F Fibonacci String Subsequences dp (看题解)
  • 原文地址:https://www.cnblogs.com/Xuman0927/p/12050866.html
Copyright © 2011-2022 走看看