Get default value of an input using jQuery

前端 未结 6 1032
梦谈多话
梦谈多话 2021-01-04 00:53
$(\".box_yazi2\").each(function () {
    var default_value = this.value;
    $(this).css(\'color\', \'#555\'); // this could be in the style sheet instead
    $(this         


        
6条回答
  •  庸人自扰
    2021-01-04 01:26

    I'm using the next code:

        //clear the focused inputs
    $('input[type="text"]').focus( function(){
        if( $(this).attr('value') == $(this).attr('defaultValue') ){
            $(this).attr('value', '');
        };
    } );
    $('input[type="text"]').blur( function(){
        if( $(this).attr('value') == '' ){
            $(this).attr('value', $(this).attr('defaultValue') );
        };
    } );
    

提交回复
热议问题