【问题标题】:Changing the input font color with readonly problem使用只读问题更改输入字体颜色
【发布时间】:2021-06-27 17:00:36
【问题描述】:

我正在尝试更改禁用输入的字体颜色。由于禁用时它是灰色的,我希望它显示为黑色。因此,我尝试使用只读,但它不起作用,现在输入没有显示它应该显示的内容。它只是说[对象对象]。这是我的 HTML 和 TS 代码。可能是什么问题?

HTML 代码:

<mat-form-field appearance="outline" fxFlex="50" class="pr-4">
                                <mat-label>Producer</mat-label>
                                <input matInput formControlName="Producer" readonly="readonly">
                                <mat-icon matSuffix class="disabled-text">short_text</mat-icon>
                                <mat-error>Producer is Mandatory!</mat-error>
                            </mat-form-field>

TS 代码:

 Producer: new FormControl(
                {
                    value:
                        this.order.ProducerSellerCode +
                        "-" +
                        this.order.ProducerSellerName,
                    readonly: true,
                },
                [Validators.required]
            ),

【问题讨论】:

  • 你能分享你的css吗?

标签: javascript html css angular typescript


【解决方案1】:

它显示 [object Object] 的原因是因为您正在为输入字段设置一个 js 对象。

如果你想改变一个只读输入的颜色,可以使用下面的css:

input:read-only {
  color: black;
}
//OR
input[readonly] {
  color: black;
}

如果您只想将其应用于选择元素,请将输入更改为类名。

【讨论】:

  • 感谢您的帮助。我将它添加到 css 文件中,但它没有改变。
  • @HecticPlatypus 您是否确认正在使用检查器应用 css?
猜你喜欢
  • 2011-09-05
  • 2021-06-27
  • 2011-12-25
  • 1970-01-01
  • 2014-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
相关资源
最近更新 更多