开发者

Form Titles with javascript

Im using this script for form titles:

$(document).ready(function(){
    $('.add-news').each( function () {
        $(this).val($(this).attr('defaultValue'));
        $(this).css({'color':'#686868' ,  'font-size':'11px', 'font-weight':'bold'});
    });
    $('.add-news').focus(function(){
        if ( $(this).val() == $(this).attr('defaultValue') ){
            $(this).val('');
            $(this).css({'color':'#686868' , 'font-size':'11px' ,'font-weight':'bold'});
        }
    });
    $('.add-news').blur(function(){
        if ($(this).val() == '' ){
            $(this).val($(this开发者_开发百科).attr('defaultValue'));
            $(this).css({'color':'#686868' ,  'font-size':'11px', 'font-weight':'bold'});
        }
    });

});

The example is here

This code working perfect for inputs, but in textarea, the above css doesnot work. How can I solve this? Thanks in advance


After removing the obvious errors ('defaultue' instead of 'defaultValue', and missing commas in the objects of the css method) it works fine for me:

http://jsfiddle.net/TY2sf/


I think the right way is using .html() instead of .val() on TextArea elements.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜