【问题标题】:Set select2 placeholder color with Jquery使用 Jquery 设置 select2 占位符颜色
【发布时间】:2016-12-21 13:12:26
【问题描述】:

所以这是使用 Css 设置颜色的方法:
.select2-container--default .select2-selection--single .select2selection__placeholder {color: #444;}

但是如何使用“this”通过 Jquery 更改颜色?

$(this).css('color', 'red') 不要工作。
$(this)[0].css('color', 'red') 不要工作。
$(this[0]).css('color', 'red') 不要工作。

编辑
console.log($this))
0:select#employment.form-control.select2.req_place

【问题讨论】:

  • 你能告诉我们你尝试了什么吗?我们不知道为什么“this”不起作用,因为我们不知道“this”指的是什么。
  • @ThEBiShOp 检查编辑..

标签: jquery css select2


【解决方案1】:

因为您的 $(this) 表明它是一个 select 元素。您需要找到它的兄弟.select2-container,这就是 UI 上显示的内容。在这个兄弟姐妹中找到.select2-selection__placeholder 并更改它的颜色。

所以使用这个代码。

$(this).siblings('.select2-container').find('.select2-selection__placeholder').css('color', 'red');

【讨论】:

  • 像魅力一样工作。完美!
  • @BjörnC 享受你的一天:D
【解决方案2】:

你也可以这样用:

.select2-search__field::placeholder{
    color: #cecfd0;
}
.select2-search__field:-ms-input-placeholder {
    color: #cecfd0;
}
.select2-search__field::-ms-input-placeholder {
    color: #cecfd0;
}

【讨论】:

    猜你喜欢
    • 2013-09-12
    • 2020-01-09
    • 2018-01-29
    • 2019-01-03
    • 2011-08-15
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    相关资源
    最近更新 更多