![](/img/trans.png)
[英]How can I set Boolean property to true or false in MongoDB with nodejs
[英]without an event for a radiobutton or checkbox, how can I set it true or false programmatically
我有一個帶有單選按鈕和復選框的頁面; 該表格之前已由用戶填寫。 我需要備份表單以供他們編輯現有數據,這意味着我必須以編程方式選中復選框並選中單選按鈕。
如果發生了事件,則可以使用srcElement輕松更改相應的控件,但是在這種情況下沒有事件。 我無法使用document.getElementById('XXX')找到方法。 ??? 以任何方式工作。
如果有幫助,請使用Angular 4。
思考?
提前致謝, :-)
使用數據綁定。 然后您可以設置更改的值,復選框和單選按鈕將自動檢查/選擇。
這是一個例子:
<label>
<input id="sendCatalogId"
type="checkbox"
[(ngModel)]="sendCatalog"
name="sendCatalog" >
Send me your catalog
</label>
和一個單選按鈕:
<label class="radio-inline">
<input type="radio" id="addressType1Id" value="home"
[(ngModel)]="addressType"
name="addressType">Home
</label>
<label class="radio-inline">
<input type="radio" id="addressType1Id" value="work"
[(ngModel)]="addressType"
name="addressType">Work
</label>
<label class="radio-inline">
<input type="radio" id="addressType1Id" value="other"
[(ngModel)]="addressType"
name="addressType">Other
</label>
這在組件類中:
...
export class CustomerComponent {
sendCatalog = false;
addressType = "home";
constructor() {
sendCatalog = true;
addressType = "work";
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.