JS基础之if判断语句

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
		/*
		 * 条件判断总结:
			1.if条件语句
			(1)if(条件){}
			 (2)if(条件1){}
			else if(条件2){}
			 (3)if(条件1){}
			 else if(条件2){}
			 else if(条件3){}
			 例1:
			 window.onload = function()
			{
				var Btn1 = document.getElementById('btn1');
				var Btn2 = document.getElementById('btn2');
				var oP = document.getElementById('p1');
				var num = 15;
				Btn1.onclick = function()
				{	if(num<22)
					{
						num++;
					oP.style.fontSize = num+'px';
					alert(num);
					}
					
					
				};
				Btn2.onclick = function()
				{
					if(num>11)
					{
						num--;
					oP.style.fontSize = num+'px';
					alert(num);
					}
					
					
				};
			};
		 */
			window.onload = function(){
				var oBtn = document.getElementById('btn');
				var oText = document.getElementById('text1');
				var oDiv = document.getElementById('div1');
				var oSpan = document.getElementById('span1');
				var oImg = document.getElementById('oimg');
				var onOff = true;
				oBtn.onclick = function()
				{
					if(oText.value=='')
					{
						alert('输入不能为空,请重新输入~~')
					}else
					{
						oDiv.innerHTML +=oSpan.innerHTML+oText.value+'</br>';
					    oText.value = '';
					}
					
				};
				
				oImg.onclick = function()
				{
					if(onOff)
					{
						oImg.src = "img/1.jpeg"
						onOff = false;
					}
					else{
						oImg.src = "img/3.jpeg"
						onOff.src = ture;
					}
				};
				
			};
			
		</script>
		<style>
			div{width:200px;height:200px;border:1px solid #9C9C9C;background: #F7F7F7;}
			img{width:200px;height:200px;}
		</style>
	</head>
	<body>
		<!--<input id="btn1" type="button" value="+"/>	
		<input id="btn2" type="button" value="-" />
		<p id="p1">让我们荡起双桨,小船儿推开波浪!!</p>-->
		<div id="div1"></div>
		<span id="span1">会话:</span>
		<input id="text1" type="text"/>
		<input id="btn" type="button" value="提交"/>
		<img id ="oimg" src="img/2.jpg"/>	
	</body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值