【问题标题】:Javascript function buttonJavascript功能按钮
【发布时间】:2016-11-11 16:40:15
【问题描述】:

我在 HTML 中创建了一个按钮:

<div class="button">
    <p id="demo"></p>           
    <button onclick="button1()">Grayscale</button>
</div>

但是,我需要链接到下面的 javascript 函数的按钮:

function clickInfoGreyscale() {
   /* Code */
}

按钮是如何链接到javascript函数的?

【问题讨论】:

  • onclick="clickInfoGreyscale()"

标签: javascript html function button


【解决方案1】:

只需将点击事件更改为触发clickInfoGreyscale() 而不是button1

function clickInfoGreyscale() {
   /* Code */
  alert('I am grey');
}
<div class="button">
    <p id="demo"></p>           
    <button onclick="clickInfoGreyscale()">Grayscale</button>
</div>

【讨论】:

    【解决方案2】:

    如果我理解正确,只需将 clickInfoGreyscale 替换为 button1 即可。

    【讨论】:

      猜你喜欢
      • 2020-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2016-05-17
      • 1970-01-01
      相关资源
      最近更新 更多