简体   繁体   English

如何使用变量而不是“禁用”字禁用字段集

[英]How do I disable a fieldsset using a variable instead of the "disable" word

I learn React JavaScript and now I have this problem.我学习了 React JavaScript,现在我遇到了这个问题。

Reading the w3schools about fieldsset阅读有关字段集的 w3schools

I wanted in this code to use the currentEditableFile if it's true to set fieldset = enabled but it's not working using the ternary as you see here:我想在这段代码中使用currentEditableFile如果设置 fieldset = enabled 但它不能使用三元组,如您在此处看到的:

<fieldset className={classes.tagssList} {currentEditableFile ? enabled: disabled}>
        <legend>Select Tags to include</legend>
        {tagsList.map(skill => (
            <button
                className="btn btn-warning btn-sm"
                disabled={false}
                key={skill}
                type="button"
                onClick={() => (currentEditableFile ? onSaveTag(skill) : null)}
            >
                {skill}
            </button>
        ))}
    </fieldset>

Please use it as below:请按如下方式使用:

<fieldset disabled={!currentEditableFile} >

Please check the working example in sandbox请检查沙箱中的工作示例

You can do it this way.你可以这样做。 Set the value of disabled equal to !currentEditableFile , which means if the currentEditableFile is true , disabled on the fieldset will be false .disabled的值设置为!currentEditableFile ,这意味着如果currentEditableFiletrue ,则fieldset上的disabled将为false

<fieldset className={classes.tagssList} disabled={!currentEditableFile}>
        <legend>Select Tags to include</legend>
        {tagsList.map(skill => (
            <button
                className="btn btn-warning btn-sm"
                disabled={false}
                key={skill}
                type="button"
                onClick={() => (currentEditableFile ? onSaveTag(skill) : null)}
            >
                {skill}
            </button>
        ))}
    </fieldset>

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

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