[英]Enable/disable textfield when a certain button is clicked on
我有一個禁用的文本字段,它也是readOnly,我試圖在您單擊某個按鈕的位置獲取它,並使文本字段啟用而不是readOnly,以便用戶可以編輯它。
到目前為止,我的代碼是這樣的:
buttonid.on({'click': function (){
if(Ext.getCmp('textfieldid').getForm().isDirty()){
Ext.getCmp('textfieldid').setDisabled(false);
}
else{
Ext.getCmp('textfieldid').setDisabled(true);
}
}});
這段代碼無法正常工作,我知道有更好的方法可以做到這一點。
您可以使用以下代碼:
buttonid.on('click', function (){
var textF = Ext.getCmp('textfieldid');
if(Ext.getCmp('textfieldid').isDirty()) {
textF.enable(); // enable textfield
textF.setReadOnly(false); // can edit field
}
else{
textF.disable(); // disable textfield
textF.setReadOnly(true); // read only is true, so can not edit
// Any way, you do not need to set field readOnly if you disable it, cause user will not be able to modify it.
}
});
這里是上述代碼中使用的方法的參考:
textfield.enable() -啟用文本字段
textfield.disable() -禁用文本字段
textfield.setReadOnly(readOnly) -是否將文本字段設置為readOnly,傳遞true / false
嘗試這個:
buttonid.on({'click': function (){
var yourTextField = Ext.getCmp('textfieldid');
if(yourTextField.getForm().isDirty()){
yourTextField.enable();
yourTextField.setReadOnly(false);
}
else{
yourTextField.disable();
yourTextField.setReadOnly(true);
}
}});
在這里,您將找到所有文本字段方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.