更改空白textarea上的背景颜色 [英] change background color on empty textarea
本文介绍了更改空白textarea上的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个id ='red'的按钮.当我单击它时,我希望那些空的文本区域变成红色. 我的代码无法正常工作.
I got a button with id='red'. When I click on it I want those textareas who are empty to turn red. My code is not working.
$(document)ready.(function() {
$('#reg').click(function() {
if($(':text').val() == '') {
$(this).css({'color':'red'});
}
});
});
非常感谢您的投入.我仍然不工作.也许是我的标记搞砸了.
Thanks a lot for your input guys. I still not working thou. Maybe it is my markup who is screwed up.
我在这里尝试了所有的提款机,但是,如果行不通的话,该死的.
I tried every sulotion here but if will not work, goddamn.
哦,我还不允许发布图片=(.我解释一下.
Oh I am no allowed to post image yet=(. I explain.
在我的网站上,我有5个文本字段,如果按注册按钮时它们为空,我希望有一个红色的背景.但前提是它们为空.
On my site I got 5 text fields that I want to have a red bg if they are empty when I press a register button. But only if they are empty.
推荐答案
尝试以下代码:
$(function() {
$('#reg').click(function() {
if($(this).text() == '') {
$(this).css({'color':'red'});
}
});
});
这篇关于更改空白textarea上的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文