我可以用CSS选择空文本区域吗? [英] Can I select empty textareas with CSS?
问题描述
有一种方法,我可以选择一个textarea, $('#id_of_textarea')。val()
在jQuery将是 '
?我尝试使用:empty
。我看到CSS提供了一种选择空输入的方式,因为文本在 value
属性( [value =]
)。
Is there a way that I can select a textarea such that $('#id_of_textarea').val()
in jQuery will be ''
? I tried using :empty
. I saw that CSS provides a way to select empty inputs because the text is in the value
attribute ([value=""]
). Is there an attribute for the text in a textarea?
我正在寻找一个可以使用CSS而不只是jQuery的选择器。
I'm looking for a selector that will work with CSS, not just jQuery.
推荐答案
最好的解决方案我可以想到的是一个CSS 3的解决方法。将字段设置为必需(并且如果需要,在提交时取消设置)。那么你可以使用
Best solution I can think of is a CSS 3 workaround. Set the field to required (and unset it on submit if need be). Then you can use
textarea:invalid { /* style here... probably want to remove box-shadow and such */ }
这篇关于我可以用CSS选择空文本区域吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!