javascript - 使用 css 更改 sweetalert 占位符颜色

标签 javascript css sweetalert

我有一个 Sweetalert如下:

swal({
                                               title: "my title",
                                               text: "",
                                               type: "input",
                                               imageUrl: "images/my_image.png",
                                               showCancelButton: true,
                                               closeOnConfirm: false,
                                               animation: "slide-from-top",
                                               inputPlaceholder: "username..."
                                               },
                                               function(inputValue){
                                               if (inputValue === false) return false;
                                               if (inputValue === "") {
                                               swal.showInputError("you didn't type anything...");
                                               return false
                                               }
                                               });

如何更改出现在 sweetalert 中的 inputPlaceholder 的颜色。我试过:

.sweet-alert input::-webkit-input-placeholder { /* Chrome/Opera/Safari */
    color: whitesmoke;
    padding-left: 4px;
}
.sweet-alert input::-moz-placeholder { /* Firefox 19+ */
    color: whitesmoke;
    padding-left: 4px;
}
.sweet-alert input:-ms-input-placeholder { /* IE 10+ */
    color: whitesmoke;
    padding-left: 4px;
}
.sweet-alert input:-moz-placeholder { /* Firefox 18- */
    color: whitesmoke;
    padding-left: 4px;
}
.inputPlaceholder {
    color: white !important;
}

最佳答案

找到解决方案。在 sweetalert.css 文件中有这些与 placehodler 相关的行:

.sweet-alert input:focus::-moz-placeholder {
        transition: opacity 0.3s 0.03s ease;
        opacity: 0.9; }
      .sweet-alert input:focus:-ms-input-placeholder {
        transition: opacity 0.3s 0.03s ease;
        opacity: 0.9; }
      .sweet-alert input:focus::-webkit-input-placeholder {
        transition: opacity 0.3s 0.03s ease;
        opacity: 0.9; }
    .sweet-alert input::-moz-placeholder {
      color: whitesmoke; }
    .sweet-alert input:-ms-input-placeholder {
      color: whitesmoke; }
    .sweet-alert input::-webkit-input-placeholder {
      color: whitesmoke; }

只需更改不透明度和颜色即可。

关于javascript - 使用 css 更改 sweetalert 占位符颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41644424/

相关文章:

javascript - 如何使用 sweetAlert js 重定向 chice 上的警报按钮?

javascript - jQuery 可排序/禁用选择问题

css - 为什么 firefox 意外地添加了 css 样式?

php - 确认和取消按钮 Laravel Sweet Alert

javascript - scrollTop 和 html 溢出 : hidden

php - Codeigniter 防止重复数据

php - Sweet Alert 2 - "confirmButtonText"按钮中的链接

javascript - 通过 ng-repeat 循环时从 dict 获取值

javascript - 如何抑制所有 JavaScript 运行时错误?

JavaScript 日历下拉菜单