单击禁用按钮时触发事件

问题描述 投票:0回答:3

单击禁用的按钮时,是否可以触发此特定功能?然后在启用按钮时触发另一个功能?

我试图做这样的骇客,但没有成功

<template>
  <b-form @submit.prevent="game">
    <b-row
      class="mt-4"
      v-on:click="invalid ? hello : ''"
    >
      <b-button
        class="auth-button"
        pill
        :disabled="invalid"
        type="submit"
      >
        重置密碼
      </b-button>
    </b-row>
  </b-form>
</template>

<script>
  data: function() {
    return {
      invalid: true
    };
  },
  methods: {
    hello() {
      alert('Hello World')
    }
    game() {
      alert('Game Over')
    }
  }
</script>
javascript vue.js bootstrap-vue
3个回答
0
投票
There is no way to capture a click on disabled elements. Your best bet is to react to a specific class on the element.

HTML Markup:

<input type="button" class="disabled" value="click" />

JavaScript code:

$('input').click(function (event) {
    if ($(this).hasClass('disabled')) {
        alert('CLICKED, BUT DISABLED!!');
    } else {
        alert('Not disabled. =)');
    }
});

0
投票

您只需要在函数名称后添加()即可使其起作用:

@click="invalid ? hello() : game()"

0
投票

为父标记创建点击事件

© www.soinside.com 2019 - 2024. All rights reserved.