【问题标题】:How to select input::placeholder using JS? [duplicate]如何使用 JS 选择 input::placeholder? [复制]
【发布时间】:2018-02-17 14:43:36
【问题描述】:

我有这个 CSS:input::placeholder {font-size: 30px}

我试图在 JS 中更改输入占位符 CSS

var inputPlaceholder = document.querySelector("input::placeholder");
inputPlaceholder.style.fontSize = "5px";

但控制台返回 Uncaught TypeError: Cannot read property 'style' of null.

如何正确更改输入占位符 CSS?

【问题讨论】:

    标签: javascript css css-selectors


    【解决方案1】:

    试试这个:

    <input type="text" style="font-size: 30px" placeholder="Here." id="new"/>
    
    var inputPlaceholder = document.getElementById('new');
    inputPlaceholder.style.fontSize = "5px";
    

    【讨论】:

      猜你喜欢
      • 2015-03-13
      • 2016-03-04
      • 1970-01-01
      • 2013-07-21
      • 2016-02-19
      • 2017-08-01
      • 2020-11-23
      • 1970-01-01
      • 2017-09-21
      相关资源
      最近更新 更多