【问题标题】:Autofocus on input in React without making the placeholder disappear until key event在 React 中自动聚焦输入而不使占位符消失,直到关键事件
【发布时间】:2015-11-21 04:29:26
【问题描述】:

我正在尝试在页面加载时将光标自动聚焦在输入上,我正在这样做:

<input placeholder="Enter text here" autoFocus={true} />

但是,当我这样做时,占位符消失了。我想让占位符显示,直到用户准备好开始输入,并且仅在关键事件上消失。你会如何在 React 中做到这一点,还是需要额外的 js/css 才能工作?

【问题讨论】:

  • 我在 Chrome 中是 not seeing this behavior。你用的是什么浏览器?
  • @Tyrsius 你是对的,忘了我下面有以下代码 - 删除它。这在 Chrome 中按预期工作。

标签: jquery html reactjs


【解决方案1】:

我意识到我的样式表中有以下内容:

::-webkit-input-placeholder {
  color: transparent;
}

删除它可以解决问题。

【讨论】:

  • 这真的很搞笑 =)
猜你喜欢
  • 1970-01-01
  • 2012-08-02
  • 2016-03-04
  • 2014-09-06
  • 2018-12-30
  • 2011-12-30
  • 2014-04-21
  • 2023-03-10
相关资源
最近更新 更多