夜光带你走进 前端工程师(三十 jS )

夜光序言:

 

 

 

 

也许一个人在真正无可奈何的时候,除了微笑,也只好微笑了。

 

 

 

 

 

正文:

 

JS   简单验证表单

                             夜光

 

1.8 :  this(自己的)

指的是本身

This  主要是指事件的动用者

className   类名

 

   $("result").className="wrong";
    $("result").innerHTML="内容不可以为空"
//  更换盒子里面的内容   文字 标签  都可以换

 

//表单更换内容    Input.value

 

 

isNaN()   nan不是一个数字  【不是一个数字】

 

下面是经典:多做几遍

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        .box{
            margin-left: 300px;
            padding: 300px;
        }
        .box span{
            border: solid;
            border-width: 1px;
            background-color: #cccccc;
            margin-left: 10px;

        }
        .wrong{
            background-color: aquamarine;
            border: 1px solid #FFAC91;
            color: #FF6B39;;
        }

    </style>
    <script>
        window.onload = function(){
            function $(id){return document.getElementById(id);}
            $("a").onblur = function(){   //离开焦点判断
               /*  alert(this.value);   //this 指 a 就近原则*/
               if(this.value == "")
               {
                   $("result").className="wrong";
                   $("result").innerHTML="内容不可以为空";
               }
                elseif(isNaN(this.value));
                {
                    $("result").className="wrong";
                    $("result").innerHTML="hellow  black";
                }
            }

        }


    </script>
</head>
<body>
<div class="box">
    线性代数:<input type="text" id="a"/><span id="result">亲,输入成绩</span>
</div>
</body>
</html>

两个小的表单验证方法

                             夜光

 

 

方法肯定有小括号

属性等号赋值

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script>
        window.onload = function(){
            var a = document.getElementById("a");
            a.focus();
        }
    </script>
</head>
<body>
自动获得焦点:
<input type="text" id="a">
</body>
</html>

 

1.9.1  表单自动获得焦点

Txt.focus();   方法

Onfocus

 

1.9.2  鼠标经过选择表单

 

// 运用select();  方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script>
        window.onload = function(){
            var a = document.getElementById("a");
            var b = document.getElementById("b");
            a.focus();    // 自动获得焦点
            b.onmouseover=function(){   //  鼠标经过选择表单
                this.select();
            }
        }
    </script>
</head>
<body>
自动获得焦点:
<input type="text" id="a">
鼠标经过选择表单:
<input type="text" id="b">
</body>
</html>

 

 For  循环

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    for(var a=0;a<=100;a++){
        if(a==0)
        {
            document.write("这个英雄已经出生<br/>");
        }
        else if(a == 26)   //else if 之间有空格
        {
            document.write("已经结婚了<br/>");
        }
        else if(a == 28) //else if 之间有空格
        {
            document.write("世界闻名<br/>");
        }
        else
        {
            document.write("飞黄腾达<br/>");
        }
    }
</script>
</body>
</html>

 

 

获取某类元素

                        夜光

 

 

1.11   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    window.onload = function(){
        var lis = document.getElementsByTagName("li");  //获得li数组  六行吧
        alert(lis.length);
    }
</script>
<ul>
    <li>123456</li>
    <li>123456</li>
    <li>123456</li>
    <li>123456</li>
    <li>123456</li>
    <li>123456</li>
</ul>
</body>
</html>

getElementsByTagName()  【可以得到很多盒子】

 

getElementById()   【可以得到一个盒子】

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    window.onload = function(){
        var lis = document.getElementsByTagName("li");  //获得li数组  六行吧
     /*   lis[3].innerHTML="abc";  // 充分理解数组这个概念*/
        alert(lis.length);        // 这个十分重要
        for(var i=0;i<=lis.length;i++){
              lis[i].innerHTML="abc";
        }
    }
</script>
<ul>
    <li>123456</li>
    <li>123456</li>
    <li>123456</li>
    <li>123456</li>
    <li>123456</li>
    <li>123456</li>
</ul>
</body>
</html>

 

//帅气

 

1:编写一个程序:计算增加后的工资

工龄满足5:增加20%

2-4:增加15%

<2:增加10%

【if else 核心】

 

2:编写一个程序

用户输出这个数,可以算出阶乘

 

 

3:for循环遍历京东图片

 

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值