Clear form inputs and keep placeholder

2020-08-04 04:12发布

问题:

I know that using this jQuery tool

$('.myDiv input').each(function () {
   $(this).val("");
});

clears my form but can anyone help me with some suggestions how to keep placeholders of the input?

Right now the placeholders appears only after I focus on at least one input.

回答1:

jQuery

function Clear()
{      
     $('.myDiv input').each(function () {
   $(this).val("");
         x=1;
    });
        $('.myDiv input').first().focus();          
}

Working Demo http://jsfiddle.net/s8vPG/2/