gpt4 book ai didi

javascript - 禁用按钮,单击另一个按钮后启用按钮

转载 作者:行者123 更新时间:2023-11-29 22:46:10 24 4
gpt4 key购买 nike

我希望在单击 Copy List To Below 之前我想禁用 Save 按钮。

目前这是Copy List To Below按钮

<button type="button" className={classes["copy-btn"] + " btn-cancel mt-3"} onClick={(event) => this.copyData(event)}>Copy List To Below {_.size(this.state.protestList) > 1 ? _.size(this.state.protestList) + " Groups" : 'Group'} </button>

这是我的保存按钮

     <button type="submit" className={classes["save-btn"] + " btn-save"} onClick={(event) => this.saveData(event)}>Save</button>

下面是尊贵的功能

    saveDate = (event, data) => {
if(event) {
//Do something
}
else {
//Return Error
}
}

copyData = (event, data) => {
if(event) {
//Do something
}
else {
//Return Error
}
}

正如我所说,只有当复制完成后,才能点击保存按钮

最佳答案

给两个 id 并像这样添加点击事件和切换按钮禁用属性。让它变得简单。您的按钮有不必要的属性,请删除它们。

核心 JAVASCRIPT

<button type="button" id="coptBtn" class ="btn-cancel mt-3" >Copy List To Below</button>
<button id="saveBtn" type="submit" class="" >Save</button>

var coptBtn = document.getElementById('coptBtn');
var saveBtn = document.getElementById('saveBtn');
saveBtn.disabled = true;
coptBtn.addEventListener('click', (evt) => {
saveBtn.disabled = false;
});

REACT JS

var App = React.createClass({
getInitialState() {
return {isDisable: false}
},
handleClick(e) {
this.setState({isDisable: true})
},
render() {
return <div>
<button type="button" onClick={this.handleClick} >Copy List To Below</button>
<button type="button" disabled={!this.state.isDisable}>Save</button>
</div>
}
});

关于javascript - 禁用按钮,单击另一个按钮后启用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58499404/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com