代码之家  ›  专栏  ›  技术社区  ›  Baz

onclick函数中的访问按钮对象

  •  -1
  • Baz  · 技术社区  · 8 年前
    <button onclick="play()" type="button">PLAY</button>
    

    如何访问播放功能中的按钮对象以禁用它?:

    function play(){
        ???.disabled = false;
    }
    
    2 回复  |  直到 8 年前
        1
  •  3
  •   Coral Kashri    8 年前

    尝试:

    function play(element) {
      element.disabled = true;
    }
    <button onclick="play(this)" type="button">PLAY</button>
        2
  •  1
  •   João Eduardo Mark_H    8 年前

    可以将button对象作为参数传递到 onclick 属性:

    <button onclick="play(this)" type="button">PLAY</button>
    

    然后在 play 功能:

    function play(button) {
       // handles the event
    }