【发布时间】:2021-05-26 16:29:48
【问题描述】:
您好,我使用过 Angular8 和 bootstrap 4。我使用过 bootstrap 多选下拉菜单,我需要将 PL Marketing 和 CL Marketing 设为禁用并变灰。我已经尝试了各种方式,但无法禁用该选项并将其变灰。
TS:
ngOnInit() {
this.initEoForm();
setTimeout(() => {
$("#multiselectUser")
.multiselect({
buttonWidth: "400px"
})
.on("change", e => {
let selectedFilename = $("#multiselectUser").val();
selectedFilename = selectedFilename.filter(function(
item,
index,
inputArray
) {
return inputArray.indexOf(item) == index;
});
let selectedName = selectedFilename
? selectedFilename.toString()
: "";
this.getSelectedRoles(selectedName);
});
}, 100);
setTimeout(() => {
$('#assignedRoles option[value="124"]').prop("disabled", true);
$('#assignedRoles option[value="123"]').prop("disabled", true);
});
}
HTML:
<select name="user" id="multiselectUser" multiple="multiple" (change)="selecteduser($event)" [(ngModel)]="selectedUsers" >
<option *ngFor="let field of user" [value]="field.id" >
{{field.label}}</option>
</select>
【问题讨论】:
-
您是否尝试在
<option>元素上使用[disabled]? -
@ХристиянХристов 感谢您的回复,但我在这里循环值所以想通过 Ts 禁用
-
所以
users[]是来自某个后端的东西,您希望动态决定应该禁用该数组中的哪些字段,对吗? -
还有其他人将 Angular 和 jQuery 混合在一起。请大家,stop doing that.
标签: javascript jquery angular