相关疑难解决方法(0)

使用jQuery选择和操作CSS伪元素,例如:: before和:: after

有没有办法使用jQuery 选择/操作CSS伪元素,如::before::after(以及带有一个分号的旧版本)?

例如,我的样式表具有以下规则:

.span::after{ content:'foo' }
Run Code Online (Sandbox Code Playgroud)

如何使用jQuery将'foo'更改为'bar'?

javascript css jquery jquery-selectors pseudo-element

897
推荐指数
14
解决办法
59万
查看次数

通过JavaScript更改CSS伪元素样式

是否可以通过JavaScript更改CSS伪元素样式?

例如,我想动态设置滚动条的颜色,如下所示:

document.querySelector("#editor::-webkit-scrollbar-thumb:vertical").style.background = localStorage.getItem("Color");
Run Code Online (Sandbox Code Playgroud)

而且我也希望能够像这样告诉滚动条隐藏:

document.querySelector("#editor::-webkit-scrollbar").style.visibility = "hidden";
Run Code Online (Sandbox Code Playgroud)

但是,这两个脚本都返回:

未捕获的TypeError:无法读取null的属性'style'

还有其他方法可以解决这个问题吗?
跨浏览器的互操作性并不重要,我只需要它在webkit浏览器中工作.

javascript css css-selectors pseudo-element selectors-api

54
推荐指数
6
解决办法
6万
查看次数

如何使用javascript更改占位符的颜色?

我想在调用mobileValidate()后更改此占位符的颜色.

<input type="text" class="form-control" name="InputMobile" id="Mobile"    placeholder="Enter Mobile Number" onblur="mobileValidate()"required>
Run Code Online (Sandbox Code Playgroud)

JavaScript函数是

function mobileValidate(){

    var x = document.getElementById("Mobile");

        if ((x.value).match(re)){
            alert("mobile Number is valid");
        }
        else{

            alert("mobile no is not valid");
            x.value="";
            x.placeholder.style.color="red";
        }

}
Run Code Online (Sandbox Code Playgroud)

html javascript css

6
推荐指数
1
解决办法
4177
查看次数