【问题标题】:Why placeholder text is not showing of textInput field in react-native?为什么占位符文本未在 react-native 中显示 textInput 字段?
【发布时间】:2019-06-14 03:41:37
【问题描述】:

我想创建一个文本输入字段,其中占位符文本将在 react-native 中显示“输入您的数字”,现在的问题是,在我按下键盘上的任何键之前,占位符文本不会显示。如果我详细说明,那么当我运行应用程序占位符文本为空时,如果我单击文本输入字段,则会出现键盘。现在,如果我按任何数字,那么它会完美地显示这些数字,如果我按十字按钮并删除我仅在该占位符文本显示时输入的所有数字。我是 react-native 的新手,所以如果有人知道这个问题,那么请在回答之前解释一下,因为到目前为止我还没有关于这个问题的任何细节。到目前为止我做了什么。

<TextInput style={styles.textField} placeholder="Enter your digit" placeholderTextColor= 'red' keyboardType= 'numeric'> </TextInput>

【问题讨论】:

    标签: react-native


    【解决方案1】:

    您的 TextInput 标记应该是自动关闭的。

    【讨论】:

    • 是的,它起作用了,两者有什么区别
    【解决方案2】:

    我认为是因为 textinput 在他的 value 属性中有一些值,你可以尝试使用value='' 吗?

     <TextInput 
      style={styles.textField} 
      placeholder="Enter your digit" 
      placeholderTextColor= 'red' 
      value=''
      keyboardType= 'numeric' />
    

    如果可行,请尝试使用 this.state.text 之类的状态值,并将初始值设为 null 或 ''(空字符串)

    【讨论】:

    • 谢谢你是对的...文本输入字段采用空字符串。 :)
    • 哦,好的。现在它正在工作。问题不在于 value 属性,而是因为标签没有自动关闭。
    • &lt;TextInput style={styles.textField} placeholder="Enter your digit" placeholderTextColor= 'red' keyboardType= 'numeric' /&gt; 这也给了我想要的结果。
    • 哦原来是标签,可能&lt;TextInput&gt; &lt;/TextInput&gt;之间的空格被取为初始值C:
    猜你喜欢
    • 2020-03-12
    • 2017-05-13
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多