【问题标题】:React — inline onfocus placeholder = ''React — 内联 onfocus 占位符 = ''
【发布时间】:2016-10-14 10:29:41
【问题描述】:

我通常使用内联 onfocus / blur 来切换输入中的占位符文本。像这样:

<input type="text" placeholder="Name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Name'"/>

这似乎在 React 中不起作用,我想知道在 React 中处理占位符切换的“正确”方法是什么。

【问题讨论】:

    标签: input reactjs toggle placeholder


    【解决方案1】:

    你仍然可以使用 React 内联:

    <input 
      type="text" 
      placeholder="Name" 
      onFocus={(e) => e.target.placeholder = ""} 
      onBlur={(e) => e.target.placeholder = "Name"} />
    

    【讨论】:

    • 它不适合我?这是因为我使用redux-form?也许 redux-form 会覆盖我的处理程序?
    猜你喜欢
    • 2018-04-10
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 2019-02-17
    • 1970-01-01
    • 2015-02-14
    • 2013-09-03
    • 1970-01-01
    相关资源
    最近更新 更多