在过去,我使用以下代码获取data-placeholder属性中的文本,并将其用作div的占位符文本。
[contentEditable=true]:empty:not(:focus):before {
content:attr(data-placeholder)
}这很有效,但在我当前的项目中,我们需要做同样的事情,除了它完全是使用jQuery构建的。我知道jQuery有.empty()、.before()、:not()和.focus()函数。按照jQuery选择器的工作方式,是否可以这样使用jQuery选择器中的CSS选择器?
var div = $([contentEditable=true]:empty:not(:focus):before);如果不是,那么在处理这么多函数时,有没有更好的方法来做到这一点?
发布于 2015-09-26 06:50:31
简单的解决方案是附加一个样式标签:
var rule ='[contentEditable=true]:empty:not(:focus):before {'+
' content:attr(data-placeholder)'+
'}';
$('head').append('<style>'+rule +'</style>');https://stackoverflow.com/questions/32791659
复制相似问题