开发者

how do i edit the font color of the initial value of form input?

开发者 https://www.devze.com 2023-02-22 22:33 出处:网络
I have created an effect on my form开发者_StackOverflow with onblur and onfocus. How do I change the colors on these onblur and onfocus elements? However, I would like to keep the user\'s input defaul

I have created an effect on my form开发者_StackOverflow with onblur and onfocus. How do I change the colors on these onblur and onfocus elements? However, I would like to keep the user's input default as black.

    $('input:text').focus(function(){
    var newValue = $(this).val();
        if($(this).val() == 'Email'){
            $(this).attr('value','');
            } else {
            $(this).val(newValue);
            }
});

$('input:text').blur(function(){
    var newValue = $(this).val();
        if($(this).val() == ''){
            $(this).attr('value','Email');
            } else {
            $(this).val(newValue);
            }
});

Thank you


Well, you don't really need javascript, css can handle focus pretty well. Just define it in your stylesheet:

input[type="text"] {color:black}
input[type="text"]:focus {color:purple}

But if you have to do it with jQuery, just use the css() function:

$(this).css({'color' : 'purple'});


This plugin I made will handle that for you: inputLabel.

Otherwise, safest is to add a class and remove the class, and put the different colour in the CSS.

0

精彩评论

暂无评论...
验证码 换一张
取 消