zoukankan      html  css  js  c++  java
  • 第26天:js-$id函数、焦点事件

    一、函数return语句
    定义函数的返回值,在函数内部用return来设置返回值,一个函数只能有一个返回值。同时,终止代码的执行。
    所有自定义函数默认没有返回值
    return后面不要换行

    var a=10,b=20,c=30;
    ++a;
    a++;
    e=++a+(++b)+(c++)+a++;
    alert(e);//77

    二、获得焦点、失去焦点事件
    获得焦点:onfocus
    失去焦点:onblur

    案例:

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>$id函数</title>
     6     <style>
     7         div{
     8             height: 100px;
     9             width: 100px;
    10             background-color: pink;
    11         }
    12     </style>
    13     <script>
    14         window.onload=function(){
    15             function $id(id){
    16             return document.getElementById(id);
    17         }
    18         $id("demo1").style.backgroundColor="red";
    19         $id("demo2").style.backgroundColor="yellow";
    20         $id("demo3").style.backgroundColor="blue";
    21 
    22             $id("btn").onclick=function(){
    23                 if($id("txt").value=="邓乐乐"){
    24                     alert("恭喜,中奖了");
    25                 }else{
    26                     alert("查无此人");
    27                 }
    28             }
    29         }
    30 
    31     </script>
    32 </head>
    33 <body>
    34 <div id="demo1"></div>
    35 <div id="demo2"></div>
    36 <div id="demo3"></div>
    37 <input type="text" id="txt" value="请输入...">
    38 <button id="btn">查询</button>
    39 </body>
    40 </html>

    运行效果:

  • 相关阅读:
    Swift
    Swift
    书籍
    Swift
    Swift
    iOS系统架构
    Reveal真机(越狱)查看任意APP
    Swift
    Swift
    Swift
  • 原文地址:https://www.cnblogs.com/le220/p/7496673.html
Copyright © 2011-2022 走看看