DOM验证账号、切换图片 、判断输入框里的值

3tests.html

<!DOCTYPE html>
<html>
  <head>
    <title>三个练习答案</title>
	
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    
    
	<script type="text/javascript">
		function check() {
			var text1EleValue = document.getElementById("text1").value;
			if(text1EleValue.length==0) {
				alert("长度不能为0!");
			} else if(text1EleValue.charAt(0)=="a"||text1EleValue.charAt(0)=="A") {
				alert("账号开头不能为A或a!");
			} else {
				alert("账号验证通过!");
			}
		}
		
		function changepicture1() {
			var img1 = document.getElementById("img");
			img1.src="197512309156.jpg";
		}
		
		function changepicture2(){
            var img2=document.getElementById("img");
            img2.attributes["src"].nodeValue="197512569446.jpg";
 
        }
        
        function checkInt(){
            var var_text2=document.getElementById("text2").value;
            if(!parseFloat(var_text2)){
                alert("请输入数字!");
            }
            else if(var_text2%1==0){
                alert("输入为整数!");
            }
            else{
                alert("不能输入浮点数!");
            }
 
        }
	</script>
	
  </head>
  
  <body>
    		<input type="text" placeholder="请输入账号" id="text1">
    		<button onclick="check()">验证</button>
    		<br>
    		<button id="button1" onclick="changepicture1()">通过src属性切换图片1</button>
    		<br>
    		<button id="button2" onclick="changepicture2()">通过属性节点切换图片1</button>
    		<br>
    		<img alt="WOW" src="197512569446.jpg" id="img" style="width: 33%;">
    		<br>
    		<input type="text" placeholder="请输入" id="text2">
    		<button id="button3"onclick="checkInt()">检查是否为整数</button>
  </body>
</html>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值