[英]How to enable/disable an input field using knockout js
我真正想要的是,如果selectedPropertyType僅是標題保險,則只需禁用該輸入字段,即“ title_servies_fee”
this.title_service_fee = ko.computed(function(){
if(this.selectedPropertyType() == 'purchase') {
return 200;
}
else if(this.selectedPropertyType() == 'cash-purchase') {
return 200;
}
else if(this.selectedPropertyType() == 'refinance') {
return 150;
}
else if(this.selectedPropertyType() == 'title-insurance-only') {
return 200;
}
else {
// here i want to disable the "title_service_fee" input field
}
}, this);
該字段是經過計算的,因此除非您使其可寫,否則不應將其綁定到輸入。
除此之外,要使輸入為只讀,您需要另一個計算您的條件的計算機,並在達到只讀條件並將該新計算的計算機綁定到輸入字段的“啟用”綁定時返回false。
您必須像這樣將data-bind
屬性添加到input
元素:
<input data-bind="disable: selectedPropertyType() === 'title-insurance-only'" />
更多信息在這里 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.