简体   繁体   English

如何根据禁用/启用按钮分配新变量?

[英]How to assign a new var based on a disabled/enabled button?

Let's say I have a button that is disabled when the condition is false (opacity: 0.3), and enabled when the condition is true (opacity: 1).假设我有一个按钮,当条件为假时禁用(不透明度:0.3),当条件为真时启用(不透明度:1)。

Let's forget about the actual condition for now -- I would like to actually check when the button is disabled (opacity: 0.3) and assign a value to a new variable based on that.现在让我们忘记实际情况——我想实际检查按钮何时被禁用(不透明度:0.3)并基于此为新变量分配一个值。

For example, if the button is disabled (opacity: 0.3), then newVar = false.例如,如果按钮被禁用(不透明度:0.3),则 newVar = false。 if the button is enabled (opacity: 1), then newVar = true.如果按钮已启用(不透明度:1),则 newVar = true。

How can I achieve that?我怎样才能做到这一点? Below is the code of my current button下面是我当前按钮的代码

<NextBtn
    orange
    withIcon
    iconStyle={{ width: '9px', height: 'auto' }}
    icon={t.image.icon.bottomChevron_orange}
    event={() => checkForError('next')}
    className="buttonNextClass"
    style={
        checkEmptyField() === true
        ? { opacity: 0.3, pointerEvents: 'none' }
        : { opacity: 1 }
    }
    >
    {c('form.content.next')}
</NextBtn>

Maybe by creating a setter to set the value of newVar :也许通过创建一个 setter 来设置newVar的值:

const setNewVar = (param)=>{
 newVar = param;
}
<NextBtn
    orange
    withIcon
    iconStyle={{ width: '9px', height: 'auto' }}
    icon={t.image.icon.bottomChevron_orange}
    event={() => checkForError('next')}
    className="buttonNextClass"
    style={
        checkEmptyField() === true
        ? setNewVar(false) && { opacity: 0.3, pointerEvents: 'none' }
        : setNewVar(true) &&  { opacity: 1 }
    }
    >
    {c('form.content.next')}
</NextBtn>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM