zoukankan      html  css  js  c++  java
  • 写出3个使用this的典型应用

    (1)、在html元素事件属性中使用,如:

    <input type=”button” onclick=”showInfo(this);” value=”点击一下” />

    (2)、构造函数

    function Animal(name, color) {
      this.name = name;
      this.color = color;
    }

    (3)、input点击,获取值

    <input type="button" id="text" value="点击一下" />
    <script type="text/javascript">
        var btn = document.getElementById("text");
        btn.onclick = function() {
            alert(this.value);    //此处的this是按钮元素
        }
    </script>

    (4)、apply()/call()求数组最值

    var  numbers = [5, 458 , 120 , -215 ]; 
    var  maxInNumbers = Math.max.apply(this, numbers);  
    console.log(maxInNumbers);  // 458
    var maxInNumbers = Math.max.call(this,5, 458 , 120 , -215); 
    console.log(maxInNumbers);  // 458

    .

  • 相关阅读:
    SIP协议
    Jenkins 使用
    JMeter测试报告
    JMeter接口测试
    JMeter学习2
    JMeter学习1
    Docker
    WebLog Expert
    sqlmap11种常见方法
    网络
  • 原文地址:https://www.cnblogs.com/crazycode2/p/10486899.html
Copyright © 2011-2022 走看看