首页 > 解决方案 > ReactJS:更改表单中的占位符颜色

问题描述

我正在尝试更改占位符颜色以允许用户知道哪些字段是强制性的。

我有一个加载表单的 Index.js:

Content = props => {
    const self = this

    return(
      <form
        className="col-12 px-sm-0 px-xs-0"
        onSubmit={e => e.preventDefault()}
        onKeyPress={(e) => {
          if (e.key === 'Enter') {
            e.preventDefault(); //<===== This stops the form from being submitted
          }
        }}
        >
        <Inizio formName={FORM_NAME} />

和 Inizio.js

export default class Inizio extends Component
{
  constructor(props)
  {
    super(props);
  }

  Fields = [
    {
      name: '$Anagraphics',
      label: 'Dati anagrafici',
      fields: [
        {
          name: 'Anagraphics.Surname',
          col: ["lg-6", 'md-6', 'sm-12'],
          label: "Cognome",
          placeholder: "Cognome",
          placeholderTextColor: "#6495ed",
          required: true,
          validate: FieldValidation.required,
          component: Fields.Text,
          normalize: value => utility.capitalizeEachWord(value)
        },

你知道我怎样才能改变占位符的颜色吗?

标签: javascriptreactjs

解决方案


If you want to access a particular element of the array use Field[index].fields[index] and then the property name. In your case it would be Fields[0].fields[0].placeholderTextColor = '#value'.


推荐阅读