onclick函数中的访问按钮对象

时间:2018-07-13 21:46:07

标签: javascript

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

如何在播放功能中访问按钮对象以将其禁用?:

function play(){
    ???.disabled = false;
}

2 个答案:

答案 0 :(得分:3)

尝试:

function play(element) {
  element.disabled = true;
}
<button onclick="play(this)" type="button">PLAY</button>

答案 1 :(得分:1)

您可以在onclick属性内将按钮对象作为参数传递:

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

,然后在play函数中将其作为参数检索:

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